diff options
author | Franck Bui <fbui@suse.com> | 2020-04-28 16:21:12 +0200 |
---|---|---|
committer | Franck Bui <fbui@suse.com> | 2020-06-11 12:00:32 +0200 |
commit | 0bb007f7a23c41e23481373ded47ee3ddcf8f26b (patch) | |
tree | 39f6adf13792ebebb45b30514a348ed752212a8a /src/core | |
parent | pid1: introduce an helper to handle the show-status marker (diff) | |
download | systemd-0bb007f7a23c41e23481373ded47ee3ddcf8f26b.tar.xz systemd-0bb007f7a23c41e23481373ded47ee3ddcf8f26b.zip |
pid1: add a new SetShowStatus() bus call to override/restore show status mode
The only way to control "ShowStatus" property programmatically was to use the
signal API and wait until the property "ShowStatus" switched to the new value.
This interface is rather cumbersome to use and doesn't allow to temporarily
override the current setting and later restore the overridden value in
race-free manner.
The new method also accepts the empty string as argument which allows to
restore the initial value of ShowStatus, ie the value before it was overridden
by this method.
Fixes: #11447.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/dbus-manager.c | 30 | ||||
-rw-r--r-- | src/core/org.freedesktop.systemd1.conf | 4 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 6763c19590..d48f529af8 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -2450,6 +2450,30 @@ static int method_abandon_scope(sd_bus_message *message, void *userdata, sd_bus_ return bus_scope_method_abandon(message, u, error); } +static int method_set_show_status(sd_bus_message *message, void *userdata, sd_bus_error *error) { + Manager *m = userdata; + ShowStatus mode = _SHOW_STATUS_INVALID; + const char *t; + int r; + + assert(m); + assert(message); + + r = sd_bus_message_read(message, "s", &t); + if (r < 0) + return r; + + if (!isempty(t)) { + mode = show_status_from_string(t); + if (mode < 0) + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid show status '%s'", t); + } + + manager_set_show_status_overridden(m, mode, "bus"); + + return sd_bus_reply_method_return(message, NULL); +} + const sd_bus_vtable bus_manager_vtable[] = { SD_BUS_VTABLE_START(0), @@ -2784,6 +2808,12 @@ const sd_bus_vtable bus_manager_vtable[] = { NULL, method_reset_failed, SD_BUS_VTABLE_UNPRIVILEGED), + SD_BUS_METHOD_WITH_NAMES("SetShowStatus", + "s", + SD_BUS_PARAM(mode), + NULL,, + method_set_show_status, + SD_BUS_VTABLE_CAPABILITY(CAP_SYS_ADMIN)), SD_BUS_METHOD_WITH_NAMES("ListUnits", NULL,, "a(ssssssouso)", diff --git a/src/core/org.freedesktop.systemd1.conf b/src/core/org.freedesktop.systemd1.conf index 415b3f5d84..9a5912c10f 100644 --- a/src/core/org.freedesktop.systemd1.conf +++ b/src/core/org.freedesktop.systemd1.conf @@ -318,6 +318,10 @@ send_interface="org.freedesktop.systemd1.Manager" send_member="AddDependencyUnitFiles"/> + <allow send_destination="org.freedesktop.systemd1" + send_interface="org.freedesktop.systemd1.Manager" + send_member="SetShowStatus"/> + <!-- Managed via polkit or other criteria: org.freedesktop.systemd1.Job interface --> <allow send_destination="org.freedesktop.systemd1" |