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