summaryrefslogtreecommitdiff
path: root/src/core/dbus-manager.c
diff options
context:
space:
mode:
authorFranck Bui <fbui@suse.com>2020-04-28 16:21:12 +0200
committerFranck Bui <fbui@suse.com>2020-06-11 12:00:32 +0200
commit0bb007f7a23c41e23481373ded47ee3ddcf8f26b (patch)
tree39f6adf13792ebebb45b30514a348ed752212a8a /src/core/dbus-manager.c
parent3ceb347130e6a3cb1df46e621e2bee8e925577f4 (diff)
downloadsystemd-0bb007f7a23c41e23481373ded47ee3ddcf8f26b.tar.gz
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/dbus-manager.c')
-rw-r--r--src/core/dbus-manager.c30
1 files changed, 30 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)",