From 721060d4469d4d9f4466d6fe707f94a2c3256fe9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 22 Nov 2017 16:34:56 +0100 Subject: [PATCH] core: allow changing the description for units dynamically at runtime This makes "systemctl set-property foobar.service Description=waldo" work. See: #7245 --- src/core/dbus-unit.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 5d4bc28..cdab461 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -1315,7 +1315,7 @@ int bus_unit_queue_job( return sd_bus_reply_method_return(message, "o", path); } -static int bus_unit_set_transient_property( +static int bus_unit_set_live_property( Unit *u, const char *name, sd_bus_message *message, @@ -1328,6 +1328,9 @@ static int bus_unit_set_transient_property( assert(name); assert(message); + /* Handles setting properties both "live" (i.e. at any time during runtime), and during creation (for transient + * units that are being created). */ + if (streq(name, "Description")) { const char *d; @@ -1344,8 +1347,28 @@ static int bus_unit_set_transient_property( } return 1; + } + + return 0; +} + +static int bus_unit_set_transient_property( + Unit *u, + const char *name, + sd_bus_message *message, + UnitWriteFlags flags, + sd_bus_error *error) { + + int r; - } else if (streq(name, "DefaultDependencies")) { + assert(u); + assert(name); + assert(message); + + /* Handles settings when transient units are created. This settings cannot be altered anymore after the unit + * has been created. */ + + if (streq(name, "DefaultDependencies")) { int b; r = sd_bus_message_read(message, "b", &b); @@ -1583,8 +1606,11 @@ int bus_unit_set_properties( r = UNIT_VTABLE(u)->bus_set_property(u, name, message, f, error); if (r == 0 && u->transient && u->load_state == UNIT_STUB) r = bus_unit_set_transient_property(u, name, message, f, error); + if (r == 0) + r = bus_unit_set_live_property(u, name, message, f, error); if (r < 0) return r; + if (r == 0) return sd_bus_error_setf(error, SD_BUS_ERROR_PROPERTY_READ_ONLY, "Cannot set property %s, or unknown property.", name); -- 2.7.4