1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "analyze.h"
4 #include "analyze-service-watchdogs.h"
5 #include "bus-error.h"
6 #include "bus-locator.h"
7 #include "parse-util.h"
8
verb_service_watchdogs(int argc,char * argv[],void * userdata)9 int verb_service_watchdogs(int argc, char *argv[], void *userdata) {
10 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
11 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
12 int b, r;
13
14 assert(IN_SET(argc, 1, 2));
15 assert(argv);
16
17 r = acquire_bus(&bus, NULL);
18 if (r < 0)
19 return bus_log_connect_error(r, arg_transport);
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 b = parse_boolean(argv[1]);
32 if (b < 0)
33 return log_error_errno(b, "Failed to parse service-watchdogs argument: %m");
34
35 r = bus_set_property(bus, bus_systemd_mgr, "ServiceWatchdogs", &error, "b", b);
36 if (r < 0)
37 return log_error_errno(r, "Failed to set service-watchdog state: %s", bus_error_message(&error, r));
38 }
39
40 return 0;
41 }
42