1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 
3 #include "bus-error.h"
4 #include "bus-locator.h"
5 #include "parse-util.h"
6 #include "systemctl-service-watchdogs.h"
7 #include "systemctl-util.h"
8 #include "systemctl.h"
9 
verb_service_watchdogs(int argc,char * argv[],void * userdata)10 int verb_service_watchdogs(int argc, char *argv[], void *userdata) {
11         sd_bus *bus;
12         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
13         int b, r;
14 
15         assert(argv);
16 
17         r = acquire_bus(BUS_MANAGER, &bus);
18         if (r < 0)
19                 return r;
20 
21         if (argc == 1) {
22                 /* get ServiceWatchdogs */
23                 r = bus_get_property_trivial(bus, bus_systemd_mgr, "ServiceWatchdogs", &error, 'b', &b);
24                 if (r < 0)
25                         return log_error_errno(r, "Failed to get service-watchdog state: %s", bus_error_message(&error, r));
26 
27                 printf("%s\n", yes_no(!!b));
28 
29         } else {
30                 /* set ServiceWatchdogs */
31                 assert(argc == 2);
32 
33                 b = parse_boolean(argv[1]);
34                 if (b < 0)
35                         return log_error_errno(b, "Failed to parse service-watchdogs argument: %m");
36 
37                 r = bus_set_property(bus, bus_systemd_mgr, "ServiceWatchdogs", &error, "b", b);
38                 if (r < 0)
39                         return log_error_errno(r, "Failed to set service-watchdog state: %s", bus_error_message(&error, r));
40         }
41 
42         return 0;
43 }
44