diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-10-13 12:56:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-13 12:56:44 +0200 |
commit | b6e44cd934873659f233bfd962e4a0dcb3026e59 (patch) | |
tree | f8f5ea7891d022cdfdc1dccf204650fce3cc23f0 /src/core | |
parent | core/bpf-firewall: add missing oom check (diff) | |
parent | watchdog: rename special string "infinity" taken by the watchdog timeout opti... (diff) | |
download | systemd-b6e44cd934873659f233bfd962e4a0dcb3026e59.tar.xz systemd-b6e44cd934873659f233bfd962e4a0dcb3026e59.zip |
Merge pull request #20787 from fbuihuu/watchdog-more-rework
Watchdog more rework
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/load-fragment.c | 29 | ||||
-rw-r--r-- | src/core/load-fragment.h | 1 | ||||
-rw-r--r-- | src/core/main.c | 46 | ||||
-rw-r--r-- | src/core/manager.c | 13 |
4 files changed, 63 insertions, 26 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 10fe579aeb..7c844a29df 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -6334,3 +6334,32 @@ int config_parse_swap_priority( s->parameters_fragment.priority_set = true; return 0; } + +int config_parse_watchdog_sec( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + assert(filename); + assert(lvalue); + assert(rvalue); + + /* This is called for {Runtime,Reboot,KExec}WatchdogSec= where "default" maps to + * USEC_INFINITY internally. */ + + if (streq(rvalue, "default")) { + usec_t *usec = data; + + *usec = USEC_INFINITY; + return 0; + } + + return config_parse_sec(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata); +} diff --git a/src/core/load-fragment.h b/src/core/load-fragment.h index 9173f30add..96ccb426e6 100644 --- a/src/core/load-fragment.h +++ b/src/core/load-fragment.h @@ -143,6 +143,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_extension_images); CONFIG_PARSER_PROTOTYPE(config_parse_bpf_foreign_program); CONFIG_PARSER_PROTOTYPE(config_parse_cgroup_socket_bind); CONFIG_PARSER_PROTOTYPE(config_parse_restrict_network_interfaces); +CONFIG_PARSER_PROTOTYPE(config_parse_watchdog_sec); /* gperf prototypes */ const struct ConfigPerfItem* load_fragment_gperf_lookup(const char *key, GPERF_LEN_TYPE length); diff --git a/src/core/main.c b/src/core/main.c index 62f39c7378..4b8e923a1e 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -537,6 +537,23 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat (void) parse_path_argument(value, false, &arg_watchdog_device); + } else if (proc_cmdline_key_streq(key, "systemd.watchdog_sec")) { + + if (proc_cmdline_value_missing(key, value)) + return 0; + + if (streq(value, "default")) + arg_runtime_watchdog = USEC_INFINITY; + else { + r = parse_sec(value, &arg_runtime_watchdog); + if (r < 0) { + log_warning_errno(r, "Failed to parse systemd.watchdog_sec= argument '%s', ignoring: %m", value); + return 0; + } + } + + arg_kexec_watchdog = arg_reboot_watchdog = arg_runtime_watchdog; + } else if (proc_cmdline_key_streq(key, "systemd.clock_usec")) { if (proc_cmdline_value_missing(key, value)) @@ -688,10 +705,10 @@ static int parse_config_file(void) { { "Manager", "NUMAPolicy", config_parse_numa_policy, 0, &arg_numa_policy.type }, { "Manager", "NUMAMask", config_parse_numa_mask, 0, &arg_numa_policy }, { "Manager", "JoinControllers", config_parse_warn_compat, DISABLED_CONFIGURATION, NULL }, - { "Manager", "RuntimeWatchdogSec", config_parse_sec, 0, &arg_runtime_watchdog }, - { "Manager", "RebootWatchdogSec", config_parse_sec, 0, &arg_reboot_watchdog }, - { "Manager", "ShutdownWatchdogSec", config_parse_sec, 0, &arg_reboot_watchdog }, /* obsolete alias */ - { "Manager", "KExecWatchdogSec", config_parse_sec, 0, &arg_kexec_watchdog }, + { "Manager", "RuntimeWatchdogSec", config_parse_watchdog_sec, 0, &arg_runtime_watchdog }, + { "Manager", "RebootWatchdogSec", config_parse_watchdog_sec, 0, &arg_reboot_watchdog }, + { "Manager", "ShutdownWatchdogSec", config_parse_watchdog_sec, 0, &arg_reboot_watchdog }, /* obsolete alias */ + { "Manager", "KExecWatchdogSec", config_parse_watchdog_sec, 0, &arg_kexec_watchdog }, { "Manager", "WatchdogDevice", config_parse_path, 0, &arg_watchdog_device }, { "Manager", "CapabilityBoundingSet", config_parse_capability_set, 0, &arg_capability_bounding_set }, { "Manager", "NoNewPrivileges", config_parse_bool, 0, &arg_no_new_privs }, @@ -1523,9 +1540,9 @@ static int become_shutdown( }; _cleanup_strv_free_ char **env_block = NULL; + usec_t watchdog_timer = 0; size_t pos = 7; int r; - usec_t watchdog_timer = 0; assert(shutdown_verb); assert(!command_line[pos]); @@ -1574,19 +1591,16 @@ static int become_shutdown( else if (streq(shutdown_verb, "kexec")) watchdog_timer = arg_kexec_watchdog; - if (timestamp_is_set(watchdog_timer)) { - /* If we reboot or kexec let's set the shutdown watchdog and tell the shutdown binary to - * repeatedly ping it */ - r = watchdog_setup(watchdog_timer); - watchdog_close(r < 0); + /* If we reboot or kexec let's set the shutdown watchdog and tell the + * shutdown binary to repeatedly ping it */ + r = watchdog_setup(watchdog_timer); + watchdog_close(r < 0); - /* Tell the binary how often to ping, ignore failure */ - (void) strv_extendf(&env_block, "WATCHDOG_USEC="USEC_FMT, watchdog_timer); + /* Tell the binary how often to ping, ignore failure */ + (void) strv_extendf(&env_block, "WATCHDOG_USEC="USEC_FMT, watchdog_timer); - if (arg_watchdog_device) - (void) strv_extendf(&env_block, "WATCHDOG_DEVICE=%s", arg_watchdog_device); - } else - watchdog_close(true); + if (arg_watchdog_device) + (void) strv_extendf(&env_block, "WATCHDOG_DEVICE=%s", arg_watchdog_device); /* Avoid the creation of new processes forked by the kernel; at this * point, we will not listen to the signals anyway */ diff --git a/src/core/manager.c b/src/core/manager.c index 6bcb6bd153..167fa1a34a 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -3215,12 +3215,8 @@ void manager_set_watchdog(Manager *m, WatchdogType t, usec_t timeout) { return; if (t == WATCHDOG_RUNTIME) - if (!timestamp_is_set(m->watchdog_overridden[WATCHDOG_RUNTIME])) { - if (timestamp_is_set(timeout)) - (void) watchdog_setup(timeout); - else - watchdog_close(true); - } + if (!timestamp_is_set(m->watchdog_overridden[WATCHDOG_RUNTIME])) + (void) watchdog_setup(timeout); m->watchdog[t] = timeout; } @@ -3238,10 +3234,7 @@ int manager_override_watchdog(Manager *m, WatchdogType t, usec_t timeout) { if (t == WATCHDOG_RUNTIME) { usec_t usec = timestamp_is_set(timeout) ? timeout : m->watchdog[t]; - if (timestamp_is_set(usec)) - (void) watchdog_setup(usec); - else - watchdog_close(true); + (void) watchdog_setup(usec); } m->watchdog_overridden[t] = timeout; |