From: Zbigniew Jędrzejewski-Szmek Date: Mon, 17 Oct 2022 12:23:04 +0000 (+0200) Subject: manager: add DumpUnitsMatchingPatternsByFileDescriptor() X-Git-Tag: v252-rc2~3^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6cce15bb30af0d28670e443ced9db7f402f1404;p=thirdparty%2Fsystemd.git manager: add DumpUnitsMatchingPatternsByFileDescriptor() --- diff --git a/man/org.freedesktop.systemd1.xml b/man/org.freedesktop.systemd1.xml index 6986ee8b037..2c9fa81e181 100644 --- a/man/org.freedesktop.systemd1.xml +++ b/man/org.freedesktop.systemd1.xml @@ -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 { + + @@ -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 systemd-analyze1's - dump command. Similarly, DumpUnitsMatchingPatterns() returns the internal - state of units whose names match the glob expressions specified in the patterns - argument. The DumpByFileDescriptor() method is identical to - Dump() 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, DumpByFileDescriptor() is usually the - preferable interface, since it ensures the data can be passed reliably from the service manager to the - client. (Note though that DumpByFileDescriptor() cannot work when communicating - with the service manager remotely, as file descriptors are strictly local to a system.) + dump command. Similarly, DumpUnitsMatchingPatterns() returns + the internal state of units whose names match the glob expressions specified in the + patterns argument. The + DumpByFileDescriptor()/DumpUnitsMatchingPatternsByFileDescriptor() + methods are identical to Dump()/DumpUnitsMatchingPatterns(), + 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, + DumpByFileDescriptor()/DumpUnitsMatchingPatternsByFileDescriptor() + 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. Reload() may be invoked to reload all unit files. diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 26d19e8ba00..e8c407c300c 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -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), diff --git a/src/core/org.freedesktop.systemd1.conf b/src/core/org.freedesktop.systemd1.conf index 66dd961c447..fe9de012b64 100644 --- a/src/core/org.freedesktop.systemd1.conf +++ b/src/core/org.freedesktop.systemd1.conf @@ -124,6 +124,10 @@ send_interface="org.freedesktop.systemd1.Manager" send_member="DumpUnitsMatchingPatterns"/> + +