From 1da7dcf427f08ae3017dd0503bdc365083081bfc Mon Sep 17 00:00:00 2001 From: David Tardon Date: Fri, 26 Sep 2025 14:58:57 +0200 Subject: [PATCH] main: extract common code to a function --- src/core/main.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index 4fc870d6c0..0f363d5c8f 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -255,6 +255,22 @@ static int console_setup(void) { return 0; } +static int parse_timeout(const char *value, usec_t *ret) { + int r = 0; + + assert(value); + assert(ret); + + if (streq(value, "default")) + *ret = USEC_INFINITY; + else if (streq(value, "off")) + *ret = 0; + else + r = parse_sec(value, ret); + + return r; +} + static int parse_proc_cmdline_item(const char *key, const char *value, void *data) { int r; @@ -456,16 +472,10 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat if (proc_cmdline_value_missing(key, value)) return 0; - if (streq(value, "default")) - arg_runtime_watchdog = USEC_INFINITY; - else if (streq(value, "off")) - arg_runtime_watchdog = 0; - 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; - } + r = parse_timeout(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; @@ -475,16 +485,10 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat if (proc_cmdline_value_missing(key, value)) return 0; - if (streq(value, "default")) - arg_pretimeout_watchdog = USEC_INFINITY; - else if (streq(value, "off")) - arg_pretimeout_watchdog = 0; - else { - r = parse_sec(value, &arg_pretimeout_watchdog); - if (r < 0) { - log_warning_errno(r, "Failed to parse systemd.watchdog_pre_sec= argument '%s', ignoring: %m", value); - return 0; - } + r = parse_timeout(value, &arg_pretimeout_watchdog); + if (r < 0) { + log_warning_errno(r, "Failed to parse systemd.watchdog_pre_sec= argument '%s', ignoring: %m", value); + return 0; } } else if (proc_cmdline_key_streq(key, "systemd.watchdog_pretimeout_governor")) {