diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-10-05 22:50:25 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-11-09 17:08:59 +0100 |
commit | c20076a8c170101fb9e6c77e4f7f84c5525dd7cc (patch) | |
tree | 1ac83867332b323f8463ac379c396d9328720dc9 /src | |
parent | 7a3025658836c536f81fdd742fa338545294f5bf (diff) | |
download | systemd-c20076a8c170101fb9e6c77e4f7f84c5525dd7cc.tar.gz systemd-c20076a8c170101fb9e6c77e4f7f84c5525dd7cc.tar.bz2 systemd-c20076a8c170101fb9e6c77e4f7f84c5525dd7cc.zip |
pid1: add a new AbandonScope() method call on the Manager object
This is the same as Abandon() on the Scope object, but saves clients
from first translating a unit name into a unit object path. This logic
matches how all the other unit methods have counterparts on the Manager
object too (e.g. StopUnit() on the Manager object matching Stop() on the
Unit object), this one was simply forgotten so far.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/dbus-manager.c | 25 | ||||
-rw-r--r-- | src/core/dbus-scope.c | 4 | ||||
-rw-r--r-- | src/core/dbus-scope.h | 2 |
3 files changed, 29 insertions, 2 deletions
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 677d9c3226..2e38088d0f 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -12,6 +12,7 @@ #include "dbus-execute.h" #include "dbus-job.h" #include "dbus-manager.h" +#include "dbus-scope.h" #include "dbus-unit.h" #include "dbus.h" #include "env-util.h" @@ -2422,6 +2423,29 @@ static int method_get_job_waiting(sd_bus_message *message, void *userdata, sd_bu return bus_job_method_get_waiting_jobs(message, j, error); } +static int method_abandon_scope(sd_bus_message *message, void *userdata, sd_bus_error *error) { + Manager *m = userdata; + const char *name; + Unit *u; + int r; + + assert(message); + assert(m); + + r = sd_bus_message_read(message, "s", &name); + if (r < 0) + return r; + + r = bus_get_unit_by_name(m, message, name, &u, error); + if (r < 0) + return r; + + if (u->type != UNIT_SCOPE) + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit '%s' is not a scope unit, refusing.", name); + + return bus_scope_method_abandon(message, u, error); +} + const sd_bus_vtable bus_manager_vtable[] = { SD_BUS_VTABLE_START(0), @@ -2537,6 +2561,7 @@ const sd_bus_vtable bus_manager_vtable[] = { SD_BUS_METHOD("StartTransientUnit", "ssa(sv)a(sa(sv))", "o", method_start_transient_unit, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("GetUnitProcesses", "s", "a(sus)", method_get_unit_processes, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("AttachProcessesToUnit", "ssau", NULL, method_attach_processes_to_unit, SD_BUS_VTABLE_UNPRIVILEGED), + SD_BUS_METHOD("AbandonScope", "s", NULL, method_abandon_scope, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("GetJob", "u", "o", method_get_job, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("GetJobAfter", "u", "a(usssoo)", method_get_job_waiting, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("GetJobBefore", "u", "a(usssoo)", method_get_job_waiting, SD_BUS_VTABLE_UNPRIVILEGED), diff --git a/src/core/dbus-scope.c b/src/core/dbus-scope.c index 6725f62794..5d9fe98857 100644 --- a/src/core/dbus-scope.c +++ b/src/core/dbus-scope.c @@ -14,7 +14,7 @@ #include "selinux-access.h" #include "unit.h" -static int bus_scope_abandon(sd_bus_message *message, void *userdata, sd_bus_error *error) { +int bus_scope_method_abandon(sd_bus_message *message, void *userdata, sd_bus_error *error) { Scope *s = userdata; int r; @@ -48,7 +48,7 @@ const sd_bus_vtable bus_scope_vtable[] = { SD_BUS_PROPERTY("TimeoutStopUSec", "t", bus_property_get_usec, offsetof(Scope, timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Scope, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_SIGNAL("RequestStop", NULL, 0), - SD_BUS_METHOD("Abandon", NULL, NULL, bus_scope_abandon, SD_BUS_VTABLE_UNPRIVILEGED), + SD_BUS_METHOD("Abandon", NULL, NULL, bus_scope_method_abandon, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_VTABLE_END }; diff --git a/src/core/dbus-scope.h b/src/core/dbus-scope.h index 7c080dbcf7..702f55898d 100644 --- a/src/core/dbus-scope.h +++ b/src/core/dbus-scope.h @@ -14,4 +14,6 @@ int bus_scope_commit_properties(Unit *u); int bus_scope_send_request_stop(Scope *s); +int bus_scope_method_abandon(sd_bus_message *message, void *userdata, sd_bus_error *error); + int bus_scope_track_controller(Scope *s); |