diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:49:52 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:49:52 +0000 |
commit | 55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch) | |
tree | 33f869f55a1b149e9b7c2b7e201867ca5dd52992 /src/systemctl/systemctl-kill.c | |
parent | Initial commit. (diff) | |
download | systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip |
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/systemctl/systemctl-kill.c')
-rw-r--r-- | src/systemctl/systemctl-kill.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/systemctl/systemctl-kill.c b/src/systemctl/systemctl-kill.c new file mode 100644 index 0000000..c4c6096 --- /dev/null +++ b/src/systemctl/systemctl-kill.c @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "bus-error.h" +#include "bus-locator.h" +#include "systemctl-kill.h" +#include "systemctl-util.h" +#include "systemctl.h" + +int verb_kill(int argc, char *argv[], void *userdata) { + _cleanup_strv_free_ char **names = NULL; + const char *kill_whom; + sd_bus *bus; + int r, q; + + r = acquire_bus(BUS_MANAGER, &bus); + if (r < 0) + return r; + + polkit_agent_open_maybe(); + + kill_whom = arg_kill_whom ?: "all"; + + /* --fail was specified */ + if (streq(arg_job_mode(), "fail")) + kill_whom = strjoina(kill_whom, "-fail"); + + r = expand_unit_names(bus, strv_skip(argv, 1), NULL, &names, NULL); + if (r < 0) + return log_error_errno(r, "Failed to expand names: %m"); + + STRV_FOREACH(name, names) { + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; + + if (arg_kill_value_set) + q = bus_call_method( + bus, + bus_systemd_mgr, + "QueueSignalUnit", + &error, + NULL, + "ssii", *name, kill_whom, arg_signal, arg_kill_value); + else + q = bus_call_method( + bus, + bus_systemd_mgr, + "KillUnit", + &error, + 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; + } + } + + return r; +} |