From 0bb007f7a23c41e23481373ded47ee3ddcf8f26b Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Tue, 28 Apr 2020 16:21:12 +0200 Subject: [PATCH] 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. --- src/core/dbus-manager.c | 30 ++++++++++++++++++++++++++ src/core/org.freedesktop.systemd1.conf | 4 ++++ 2 files changed, 34 insertions(+) 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"/> + +