summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-02-21 10:52:49 +0100
committerLennart Poettering <lennart@poettering.net>2022-02-21 17:22:23 +0100
commit2b04e72cd19286e58a8234e282e6c1a32d473b0d (patch)
tree4230b2708182e8fc1e8e02faac51294ad6d3e93e
parentanalyze: split out "dot" verb (diff)
downloadsystemd-2b04e72cd19286e58a8234e282e6c1a32d473b0d.tar.xz
systemd-2b04e72cd19286e58a8234e282e6c1a32d473b0d.zip
analyze: split out "service-watchdogs" verb
-rw-r--r--src/analyze/analyze-service-watchdogs.c41
-rw-r--r--src/analyze/analyze-service-watchdogs.h4
-rw-r--r--src/analyze/analyze.c35
-rw-r--r--src/analyze/meson.build2
4 files changed, 48 insertions, 34 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;
+}
diff --git a/src/analyze/analyze-service-watchdogs.h b/src/analyze/analyze-service-watchdogs.h
new file mode 100644
index 0000000000..11a53dbbf1
--- /dev/null
+++ b/src/analyze/analyze-service-watchdogs.h
@@ -0,0 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+int service_watchdogs(int argc, char *argv[], void *userdata);
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index 8326cfa49e..bbf5f8439a 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -20,6 +20,7 @@
#include "analyze-elf.h"
#include "analyze-filesystems.h"
#include "analyze-security.h"
+#include "analyze-service-watchdogs.h"
#include "analyze-syscall-filter.h"
#include "analyze-timespan.h"
#include "analyze-timestamp.h"
@@ -1413,40 +1414,6 @@ void time_parsing_hint(const char *p, bool calendar, bool timestamp, bool timesp
"Use 'systemd-analyze timespan \"%s\"' instead?", p);
}
-static 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;
-}
-
static int do_condition(int argc, char *argv[], void *userdata) {
return verify_conditions(strv_skip(argv, 1), arg_scope, arg_unit, arg_root);
}
diff --git a/src/analyze/meson.build b/src/analyze/meson.build
index 922a343e69..c992e20c46 100644
--- a/src/analyze/meson.build
+++ b/src/analyze/meson.build
@@ -15,6 +15,8 @@ systemd_analyze_sources = files('''
analyze-filesystems.h
analyze-security.c
analyze-security.h
+ analyze-service-watchdogs.c
+ analyze-service-watchdogs.h
analyze-syscall-filter.c
analyze-syscall-filter.h
analyze-timespan.c