]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
main: extract common code to a function
authorDavid Tardon <dtardon@redhat.com>
Fri, 26 Sep 2025 12:58:57 +0000 (14:58 +0200)
committerDavid Tardon <dtardon@redhat.com>
Thu, 2 Oct 2025 14:13:40 +0000 (16:13 +0200)
src/core/main.c

index 4fc870d6c0eefb5282c2754b4ef48b8651b14e39..0f363d5c8fab3618abe1648a6fb9b5159fa6634a 100644 (file)
@@ -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")) {