diff options
Diffstat (limited to '')
-rw-r--r-- | src/systemctl/systemctl-kill.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/systemctl/systemctl-kill.c b/src/systemctl/systemctl-kill.c index c4c6096..4c1829e 100644 --- a/src/systemctl/systemctl-kill.c +++ b/src/systemctl/systemctl-kill.c @@ -2,11 +2,13 @@ #include "bus-error.h" #include "bus-locator.h" +#include "bus-wait-for-units.h" #include "systemctl-kill.h" #include "systemctl-util.h" #include "systemctl.h" int verb_kill(int argc, char *argv[], void *userdata) { + _cleanup_(bus_wait_for_units_freep) BusWaitForUnits *w = NULL; _cleanup_strv_free_ char **names = NULL; const char *kill_whom; sd_bus *bus; @@ -16,6 +18,12 @@ int verb_kill(int argc, char *argv[], void *userdata) { if (r < 0) return r; + if (arg_wait) { + r = bus_wait_for_units_new(bus, &w); + if (r < 0) + return log_error_errno(r, "Failed to allocate unit watch context: %m"); + } + polkit_agent_open_maybe(); kill_whom = arg_kill_whom ?: "all"; @@ -48,11 +56,24 @@ int verb_kill(int argc, char *argv[], void *userdata) { NULL, "ssi", *name, kill_whom, arg_signal); if (q < 0) { - log_error_errno(q, "Failed to kill unit %s: %s", *name, bus_error_message(&error, q)); - if (r == 0) - r = q; + RET_GATHER(r, log_error_errno(q, "Failed to kill unit %s: %s", *name, bus_error_message(&error, q))); + continue; + } + + if (w) { + q = bus_wait_for_units_add_unit(w, *name, BUS_WAIT_FOR_INACTIVE|BUS_WAIT_NO_JOB, NULL, NULL); + if (q < 0) + RET_GATHER(r, log_error_errno(q, "Failed to watch unit %s: %m", *name)); } } + if (w) { + q = bus_wait_for_units_run(w); + if (q < 0) + return log_error_errno(q, "Failed to wait for units: %m"); + if (q == BUS_WAIT_FAILURE) + RET_GATHER(r, -EIO); + } + return r; } |