mirror of
https://github.com/systemd/systemd.git
synced 2025-01-25 10:04:04 +03:00
analyze: split out "service-watchdogs" verb
This commit is contained in:
parent
cccd2af6f5
commit
2b04e72cd1
41
src/analyze/analyze-service-watchdogs.c
Normal file
41
src/analyze/analyze-service-watchdogs.c
Normal file
@ -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;
|
||||
}
|
4
src/analyze/analyze-service-watchdogs.h
Normal file
4
src/analyze/analyze-service-watchdogs.h
Normal file
@ -0,0 +1,4 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
int service_watchdogs(int argc, char *argv[], void *userdata);
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user