]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: change kernel commandline option parsing
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 22 Oct 2016 18:38:49 +0000 (14:38 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 22 Oct 2016 18:42:12 +0000 (14:42 -0400)
- do not crash if an option without value is specified on the kernel command
  line, e.g. "udev.log-priority" :P
- simplify the code a bit
- warn about unknown "udev.*" options — this should make it easier to spot
  typos and reduce user confusion

src/udev/udevd.c

index 601ab69f1b8574ec09bd485535c5d7146bbe878d..05cd5079c1412f377d04f19f1372c0ad6775a6b3 100644 (file)
@@ -1363,8 +1363,7 @@ static int listen_fds(int *rctrl, int *rnetlink) {
  *   udev.event-timeout=<number of seconds>    seconds to wait before terminating an event
  */
 static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
  *   udev.event-timeout=<number of seconds>    seconds to wait before terminating an event
  */
 static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
-        const char *full_key = key;
-        int r;
+        int r = 0;
 
         assert(key);
 
 
         assert(key);
 
@@ -1374,37 +1373,25 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
         if (startswith(key, "rd."))
                 key += strlen("rd.");
 
         if (startswith(key, "rd."))
                 key += strlen("rd.");
 
-        if (startswith(key, "udev."))
-                key += strlen("udev.");
-        else
-                return 0;
-
-        if (streq(key, "log-priority")) {
-                int prio;
-
-                prio = util_log_priority(value);
-                if (prio < 0)
-                        goto invalid;
-                log_set_max_level(prio);
-        } else if (streq(key, "children-max")) {
+        if (streq(key, "udev.log-priority") && value) {
+                r = util_log_priority(value);
+                if (r >= 0)
+                        log_set_max_level(r);
+        } else if (streq(key, "udev.event-timeout") && value) {
+                r = safe_atou64(value, &arg_event_timeout_usec);
+                if (r >= 0) {
+                        arg_event_timeout_usec *= USEC_PER_SEC;
+                        arg_event_timeout_warn_usec = (arg_event_timeout_usec / 3) ? : 1;
+                }
+        } else if (streq(key, "udev.children-max") && value)
                 r = safe_atou(value, &arg_children_max);
                 r = safe_atou(value, &arg_children_max);
-                if (r < 0)
-                        goto invalid;
-        } else if (streq(key, "exec-delay")) {
+        else if (streq(key, "udev.exec-delay") && value)
                 r = safe_atoi(value, &arg_exec_delay);
                 r = safe_atoi(value, &arg_exec_delay);
-                if (r < 0)
-                        goto invalid;
-        } else if (streq(key, "event-timeout")) {
-                r = safe_atou64(value, &arg_event_timeout_usec);
-                if (r < 0)
-                        goto invalid;
-                arg_event_timeout_usec *= USEC_PER_SEC;
-                arg_event_timeout_warn_usec = (arg_event_timeout_usec / 3) ? : 1;
-        }
+        else if (startswith(key, "udev."))
+                log_warning("Unknown udev kernel command line option \"%s\"", key);
 
 
-        return 0;
-invalid:
-        log_warning("invalid %s ignored: %s", full_key, value);
+        if (r < 0)
+                log_warning_errno(r, "Failed to parse \"%s=%s\", ignoring: %m", key, value);
         return 0;
 }
 
         return 0;
 }