diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-02-21 10:52:49 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-02-21 17:22:23 +0100 |
commit | 2b04e72cd19286e58a8234e282e6c1a32d473b0d (patch) | |
tree | 4230b2708182e8fc1e8e02faac51294ad6d3e93e /src/analyze/analyze-service-watchdogs.c | |
parent | cccd2af6f579fa63deafdde51014474f78d99958 (diff) | |
download | systemd-2b04e72cd19286e58a8234e282e6c1a32d473b0d.tar.gz |
analyze: split out "service-watchdogs" verb
Diffstat (limited to 'src/analyze/analyze-service-watchdogs.c')
-rw-r--r-- | src/analyze/analyze-service-watchdogs.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/analyze/analyze-service-watchdogs.c b/src/analyze/analyze-service-watchdogs.c new file mode 100644 index 0000000000..7b804bd90b --- /dev/null +++ b/src/analyze/analyze-service-watchdogs.c @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "analyze.h" +#include "analyze-service-watchdogs.h" +#include "bus-error.h" +#include "bus-locator.h" +#include "parse-util.h" + +int service_watchdogs(int argc, char *argv[], void *userdata) { + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; + int b, r; + + assert(IN_SET(argc, 1, 2)); + assert(argv); + + r = acquire_bus(&bus, NULL); + if (r < 0) + return bus_log_connect_error(r, arg_transport); + + if (argc == 1) { + /* get ServiceWatchdogs */ + r = bus_get_property_trivial(bus, bus_systemd_mgr, "ServiceWatchdogs", &error, 'b', &b); + if (r < 0) + return log_error_errno(r, "Failed to get service-watchdog state: %s", bus_error_message(&error, r)); + + printf("%s\n", yes_no(!!b)); + + } else { + /* set ServiceWatchdogs */ + b = parse_boolean(argv[1]); + if (b < 0) + return log_error_errno(b, "Failed to parse service-watchdogs argument: %m"); + + r = bus_set_property(bus, bus_systemd_mgr, "ServiceWatchdogs", &error, "b", b); + if (r < 0) + return log_error_errno(r, "Failed to set service-watchdog state: %s", bus_error_message(&error, r)); + } + + return 0; +} |