diff options
author | Tom Gundersen <teg@jklm.no> | 2015-04-17 23:18:24 +0200 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2015-05-26 11:44:59 -0400 |
commit | c05ef0c2e24fcaef4d76a3409b165bc643f33ecc (patch) | |
tree | fd47bac95e98e895047bd7019f6adba1378c5991 | |
parent | 97862d111887e7295c2074f78b629fae10c19dd0 (diff) |
udevd: use kernel cmdline parser
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
-rw-r--r-- | src/udev/udevd.c | 79 |
1 files changed, 36 insertions, 43 deletions
diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 98c7feeec0..64ef25f38a 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -987,60 +987,51 @@ static void event_queue_update(void) { /* * read the kernel command line, in case we need to get into debug mode - * udev.log-priority=<level> syslog priority - * udev.children-max=<number of workers> events are fully serialized if set to 1 - * udev.exec-delay=<number of seconds> delay execution of every executed program + * udev.log-priority=<level> syslog priority + * udev.children-max=<number of workers> events are fully serialized if set to 1 + * udev.exec-delay=<number of seconds> delay execution of every executed program + * udev.event-timeout=<number of seconds> seconds to wait before terminating an event */ -static void kernel_cmdline_options(struct udev *udev) { - _cleanup_free_ char *line = NULL; - const char *word, *state; - size_t l; +static int parse_proc_cmdline_item(const char *key, const char *value) { int r; - r = proc_cmdline(&line); - if (r < 0) { - log_warning_errno(r, "Failed to read /proc/cmdline, ignoring: %m"); - return; - } + assert(key); - FOREACH_WORD_QUOTED(word, l, line, state) { - char *s, *opt, *value; + if (!value) + return 0; - s = strndup(word, l); - if (!s) - break; + if (startswith(key, "rd.")) + key += strlen("rd."); - /* accept the same options for the initrd, prefixed with "rd." */ - if (in_initrd() && startswith(s, "rd.")) - opt = s + 3; - else - opt = s; + if (startswith(key, "udev.")) + key += strlen("udev."); + else + return 0; - if ((value = startswith(opt, "udev.log-priority="))) { - int prio; + if (streq(key, "log-priority")) { + int prio; - prio = util_log_priority(value); - log_set_max_level(prio); - } else if ((value = startswith(opt, "udev.children-max="))) { - r = safe_atoi(value, &arg_children_max); - if (r < 0) - log_warning("Invalid udev.children-max ignored: %s", value); - } else if ((value = startswith(opt, "udev.exec-delay="))) { - r = safe_atoi(value, &arg_exec_delay); - if (r < 0) - log_warning("Invalid udev.exec-delay ignored: %s", value); - } else if ((value = startswith(opt, "udev.event-timeout="))) { - r = safe_atou64(value, &arg_event_timeout_usec); - if (r < 0) { - log_warning("Invalid udev.event-timeout ignored: %s", value); - break; - } + prio = util_log_priority(value); + log_set_max_level(prio); + } else if (streq(key, "children-max")) { + r = safe_atoi(value, &arg_children_max); + if (r < 0) + log_warning("invalid udev.children-max ignored: %s", value); + } else if (streq(key, "exec-delay")) { + r = safe_atoi(value, &arg_exec_delay); + if (r < 0) + log_warning("invalid udev.exec-delay ignored: %s", value); + } else if (streq(key, "event-timeout")) { + r = safe_atou64(value, &arg_event_timeout_usec); + if (r < 0) + log_warning("invalid udev.event-timeout ignored: %s", value); + else { arg_event_timeout_usec *= USEC_PER_SEC; arg_event_timeout_warn_usec = (arg_event_timeout_usec / 3) ? : 1; } - - free(s); } + + return 0; } static void help(void) { @@ -1160,7 +1151,9 @@ int main(int argc, char *argv[]) { if (r <= 0) goto exit; - kernel_cmdline_options(udev); + r = parse_proc_cmdline(parse_proc_cmdline_item); + if (r < 0) + log_warning_errno(r, "failed to parse kernel command line, ignoring: %m"); if (arg_debug) log_set_max_level(LOG_DEBUG); |