1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-09 01:18:19 +03:00

manager: add DumpUnitsMatchingPatternsByFileDescriptor()

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-10-17 14:23:04 +02:00
parent 293b9aa3eb
commit f6cce15bb3
3 changed files with 39 additions and 11 deletions

View File

@ -165,6 +165,8 @@ node /org/freedesktop/systemd1 {
DumpUnitsMatchingPatterns(in as patterns,
out s output);
DumpByFileDescriptor(out h fd);
DumpUnitsMatchingPatternsByFileDescriptor(in as patterns,
out h fd);
Reload();
@org.freedesktop.DBus.Method.NoReply("true")
Reexecute();
@ -874,6 +876,8 @@ node /org/freedesktop/systemd1 {
<variablelist class="dbus-method" generated="True" extra-ref="DumpByFileDescriptor()"/>
<variablelist class="dbus-method" generated="True" extra-ref="DumpUnitsMatchingPatternsByFileDescriptor()"/>
<variablelist class="dbus-method" generated="True" extra-ref="Reload()"/>
<variablelist class="dbus-method" generated="True" extra-ref="Reexecute()"/>
@ -1342,15 +1346,18 @@ node /org/freedesktop/systemd1 {
string guaranteed, and new fields may be added any time, and old fields removed. The general structure
may be rearranged drastically between releases. This is exposed by
<citerefentry><refentrytitle>systemd-analyze</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
<command>dump</command> command. Similarly, <function>DumpUnitsMatchingPatterns()</function> returns the internal
state of units whose names match the glob expressions specified in the <varname>patterns</varname>
argument. The <function>DumpByFileDescriptor()</function> method is identical to
<function>Dump()</function> but returns the data serialized into a file descriptor (the client should
read the text data from it until hitting EOF). Given the size limits on D-Bus messages and the possibly
large size of the returned string, <function>DumpByFileDescriptor()</function> is usually the
preferable interface, since it ensures the data can be passed reliably from the service manager to the
client. (Note though that <function>DumpByFileDescriptor()</function> cannot work when communicating
with the service manager remotely, as file descriptors are strictly local to a system.)</para>
<command>dump</command> command. Similarly, <function>DumpUnitsMatchingPatterns()</function> returns
the internal state of units whose names match the glob expressions specified in the
<varname>patterns</varname> argument. The
<function>DumpByFileDescriptor()</function>/<function>DumpUnitsMatchingPatternsByFileDescriptor()</function>
methods are identical to <function>Dump()</function>/<function>DumpUnitsMatchingPatterns()</function>,
but return data serialized into a file descriptor (the client should read the text data from it until
hitting EOF). Given the size limits on D-Bus messages and the possibly large size of the returned
strings,
<function>DumpByFileDescriptor()</function>/<function>DumpUnitsMatchingPatternsByFileDescriptor()</function>
are usually the preferred interface, since it ensures the data can be passed reliably from the service
manager to the client. Note though that they cannot work when communicating with the service manager
remotely, as file descriptors are strictly local to a system.</para>
<para><function>Reload()</function> may be invoked to reload all unit files.</para>

View File

@ -1392,7 +1392,11 @@ static int method_dump_by_fd(sd_bus_message *message, void *userdata, sd_bus_err
return dump_impl(message, userdata, error, NULL, reply_dump_by_fd);
}
static int method_dump_units_matching_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error) {
static int dump_units_matching_patterns(
sd_bus_message *message,
void *userdata,
sd_bus_error *error,
int (*reply)(sd_bus_message *, char *)) {
_cleanup_strv_free_ char **patterns = NULL;
int r;
@ -1400,7 +1404,15 @@ static int method_dump_units_matching_patterns(sd_bus_message *message, void *us
if (r < 0)
return r;
return dump_impl(message, userdata, error, patterns, reply_dump);
return dump_impl(message, userdata, error, patterns, reply);
}
static int method_dump_units_matching_patterns(sd_bus_message *message, void *userdata, sd_bus_error *error) {
return dump_units_matching_patterns(message, userdata, error, reply_dump);
}
static int method_dump_units_matching_patterns_by_fd(sd_bus_message *message, void *userdata, sd_bus_error *error) {
return dump_units_matching_patterns(message, userdata, error, reply_dump_by_fd);
}
static int method_refuse_snapshot(sd_bus_message *message, void *userdata, sd_bus_error *error) {
@ -3037,6 +3049,11 @@ const sd_bus_vtable bus_manager_vtable[] = {
SD_BUS_RESULT("h", fd),
method_dump_by_fd,
SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD_WITH_ARGS("DumpUnitsMatchingPatternsByFileDescriptor",
SD_BUS_ARGS("as", patterns),
SD_BUS_RESULT("h", fd),
method_dump_units_matching_patterns_by_fd,
SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD_WITH_ARGS("CreateSnapshot",
SD_BUS_ARGS("s", name, "b", cleanup),
SD_BUS_RESULT("o", unit),

View File

@ -124,6 +124,10 @@
send_interface="org.freedesktop.systemd1.Manager"
send_member="DumpUnitsMatchingPatterns"/>
<allow send_destination="org.freedesktop.systemd1"
send_interface="org.freedesktop.systemd1.Manager"
send_member="DumpUnitsMatchingPatternsByFileDescriptor"/>
<allow send_destination="org.freedesktop.systemd1"
send_interface="org.freedesktop.systemd1.Manager"
send_member="ListUnitFiles"/>