Debian Codegraph @

src/systemctl/systemctl-reset-failed.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "sd-bus.h"
4
5 #include "bus-error.h"
6 #include "bus-locator.h"
7 #include "log.h"
8 #include "strv.h"
9 #include "systemctl-reset-failed.h"
10 #include "systemctl-trivial-method.h"
11 #include "systemctl-util.h"
12
13 int verb_reset_failed(int argc, char *argv[], uintptr_t data, void *userdata) {
14 _cleanup_strv_free_ char **names = NULL;
15 sd_bus *bus;
16 int r, q;
17
18 if (argc <= 1) /* Shortcut to trivial_method() if no argument is given */
19 return verb_trivial_method(argc, argv, data, userdata);
20
21 r = acquire_bus(BUS_MANAGER, &bus);
22 if (r < 0)
23 return r;
24
25 polkit_agent_open_maybe();
26
27 r = expand_unit_names(bus, strv_skip(argv, 1), NULL, &names, NULL);
28 if (r < 0)
29 return log_error_errno(r, "Failed to expand names: %m");
30
31 STRV_FOREACH(name, names) {
32 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
33
34 q = bus_call_method(bus, bus_systemd_mgr, "ResetFailedUnit", &error, NULL, "s", *name);
35 if (q < 0) {
36 log_error_errno(q, "Failed to reset failed state of unit %s: %s", *name, bus_error_message(&error, q));
37 if (r == 0)
38 r = q;
39 }
40 }
41
42 return r;
43 }