]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/systemctl/systemctl-kill.c
efeff44e0f84b5e092dd65d1f2555d448971f42a
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
6 #include "bus-locator.h"
7 #include "bus-wait-for-units.h"
8 #include "errno-util.h"
10 #include "string-util.h"
12 #include "systemctl.h"
13 #include "systemctl-kill.h"
14 #include "systemctl-util.h"
16 int verb_kill(int argc
, char *argv
[], void *userdata
) {
17 _cleanup_(bus_wait_for_units_freep
) BusWaitForUnits
*w
= NULL
;
18 _cleanup_strv_free_
char **names
= NULL
;
19 const char *kill_whom
;
23 r
= acquire_bus(BUS_MANAGER
, &bus
);
28 r
= bus_wait_for_units_new(bus
, &w
);
30 return log_error_errno(r
, "Failed to allocate unit watch context: %m");
33 polkit_agent_open_maybe();
35 kill_whom
= arg_kill_whom
?: "all";
37 /* --fail was specified */
38 if (streq(arg_job_mode(), "fail"))
39 kill_whom
= strjoina(kill_whom
, "-fail");
41 r
= expand_unit_names(bus
, strv_skip(argv
, 1), NULL
, &names
, NULL
);
43 return log_error_errno(r
, "Failed to expand names: %m");
45 STRV_FOREACH(name
, names
) {
46 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
48 if (arg_kill_value_set
)
55 "ssii", *name
, kill_whom
, arg_signal
, arg_kill_value
);
63 "ssi", *name
, kill_whom
, arg_signal
);
65 RET_GATHER(r
, log_error_errno(q
, "Failed to kill unit %s: %s", *name
, bus_error_message(&error
, q
)));
70 q
= bus_wait_for_units_add_unit(w
, *name
, BUS_WAIT_FOR_INACTIVE
|BUS_WAIT_NO_JOB
, NULL
, NULL
);
72 RET_GATHER(r
, log_error_errno(q
, "Failed to watch unit %s: %m", *name
));
77 q
= bus_wait_for_units_run(w
);
79 return log_error_errno(q
, "Failed to wait for units: %m");
80 if (q
== BUS_WAIT_FAILURE
)