]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevd: allow more parameters to be set through udev.conf
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 13 Nov 2018 10:10:13 +0000 (11:10 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 13 Nov 2018 13:03:47 +0000 (14:03 +0100)
Rebooting to set change the kernel command line to set some udev parameters is
inconvenient. Let's allow setting more stuff in the config file.

Also drop quotes from around "info" in udev.conf. We need to accept them for
compatibility, but there is no reason to use them.

man/udev.conf.xml
src/shared/udev-util.c
src/shared/udev-util.h
src/udev/udev.conf
src/udev/udevd.c

index 29c9743d1d6e9d8951530ff31d215357584c1478..7b7cae16b20b010c8f8e810e42333042df10a7f5 100644 (file)
@@ -42,7 +42,7 @@
 
     <variablelist>
       <varlistentry>
-        <term><varname>udev_log</varname></term>
+        <term><varname>udev_log=</varname></term>
 
         <listitem>
           <para>The log level. Valid values are the numerical
           <option>debug</option>.</para>
         </listitem>
       </varlistentry>
+
+      <varlistentry>
+        <term><varname>children_max=</varname></term>
+
+        <listitem>
+          <para>An integer. The maximum number of events executed in parallel.</para>
+
+          <para>This is the same as the <option>--children-max=</option> option.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term><varname>exec_delay=</varname></term>
+
+        <listitem>
+          <para>An integer. Delay the execution of <varname>RUN</varname>
+          instructions by the given number of seconds. This option
+          might be useful when debugging system crashes during
+          coldplug caused by loading non-working kernel
+          modules.</para>
+
+          <para>This is the same as the <option>--exec-delay=</option> option.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term><varname>event_timeout=</varname></term>
+
+        <listitem>
+          <para>An integer. The number of seconds to wait for events to finish. After
+          this time, the event will be terminated. The default is 180 seconds.</para>
+
+          <para>This is the same as the <option>--event-timeout=</option> option.</para>
+        </listitem>
+      </varlistentry>
+
     </variablelist>
 
     <para>
index a603867b16e3e5863c373455273dc04d65a0ec8e..057aabcd5428baca7808eda185a4c4dc92fbbacf 100644 (file)
@@ -6,36 +6,68 @@
 #include "alloc-util.h"
 #include "fileio.h"
 #include "log.h"
+#include "parse-util.h"
 #include "string-util.h"
 #include "udev-util.h"
+#include "udev.h"
 
-int udev_parse_config(void) {
-        _cleanup_free_ char *val = NULL;
-        const char *log;
-        size_t n;
+int udev_parse_config_full(
+                unsigned *ret_children_max,
+                usec_t *ret_exec_delay_usec,
+                usec_t *ret_event_timeout_usec) {
+
+        _cleanup_free_ char *log_val = NULL, *children_max = NULL, *exec_delay = NULL, *event_timeout = NULL;
         int r;
 
-        r = parse_env_file(NULL, "/etc/udev/udev.conf", NEWLINE, "udev_log", &val, NULL);
-        if (r == -ENOENT || !val)
+        r = parse_env_file(NULL, "/etc/udev/udev.conf", NEWLINE,
+                           "udev_log", &log_val,
+                           "children_max", &children_max,
+                           "exec_delay", &exec_delay,
+                           "event_timeout", &event_timeout,
+                           NULL);
+        if (r == -ENOENT)
                 return 0;
         if (r < 0)
                 return r;
 
-        /* unquote */
-        n = strlen(val);
-        if (n >= 2 &&
-            ((val[0] == '"' && val[n-1] == '"') ||
-             (val[0] == '\'' && val[n-1] == '\''))) {
-                val[n - 1] = '\0';
-                log = val + 1;
-        } else
-                log = val;
-
-        /* we set the udev log level here explicitly, this is supposed
-         * to regulate the code in libudev/ and udev/. */
-        r = log_set_max_level_from_string_realm(LOG_REALM_UDEV, log);
-        if (r < 0)
-                log_debug_errno(r, "/etc/udev/udev.conf: failed to set udev log level '%s', ignoring: %m", log);
+        if (log_val) {
+                const char *log;
+                size_t n;
+
+                /* unquote */
+                n = strlen(log_val);
+                if (n >= 2 &&
+                    ((log_val[0] == '"' && log_val[n-1] == '"') ||
+                     (log_val[0] == '\'' && log_val[n-1] == '\''))) {
+                        log_val[n - 1] = '\0';
+                        log = log_val + 1;
+                } else
+                        log = log_val;
+
+                /* we set the udev log level here explicitly, this is supposed
+                 * to regulate the code in libudev/ and udev/. */
+                r = log_set_max_level_from_string_realm(LOG_REALM_UDEV, log);
+                if (r < 0)
+                        log_debug_errno(r, "/etc/udev/udev.conf: failed to set udev log level '%s', ignoring: %m", log);
+        }
+
+        if (ret_children_max && children_max) {
+                r = safe_atou(children_max, ret_children_max);
+                if (r < 0)
+                        log_notice_errno(r, "/etc/udev/udev.conf: failed to set parse children_max=%s, ignoring: %m", children_max);
+        }
+
+        if (ret_exec_delay_usec && exec_delay) {
+                r = parse_sec(exec_delay, ret_exec_delay_usec);
+                if (r < 0)
+                        log_notice_errno(r, "/etc/udev/udev.conf: failed to set parse exec_delay=%s, ignoring: %m", exec_delay);
+        }
+
+        if (ret_event_timeout_usec && event_timeout) {
+                r = parse_sec(event_timeout, ret_event_timeout_usec);
+                if (r < 0)
+                        log_notice_errno(r, "/etc/udev/udev.conf: failed to set parse event_timeout=%s, ignoring: %m", event_timeout);
+        }
 
         return 0;
 }
index 0df2cf9eb19b63f1e5a53b44fbbe0bdc53aa1f0e..efbcd82976fc38efffdcc0a9172e651067df8d3d 100644 (file)
@@ -1,4 +1,13 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 #pragma once
 
-int udev_parse_config(void);
+#include "time-util.h"
+
+int udev_parse_config_full(
+                unsigned *ret_children_max,
+                usec_t *ret_exec_delay_usec,
+                usec_t *ret_event_timeout_usec);
+
+static inline int udev_parse_config(void) {
+        return udev_parse_config_full(NULL, NULL, NULL);
+}
index 0d812d4a6565309658874c8745f22975f5d0ada6..3395a8b7ea6099cbf181c11b12dcf1ae6ef1b94c 100644 (file)
@@ -3,4 +3,7 @@
 # udevd is also started in the initrd.  When this file is modified you might
 # also want to rebuild the initrd, so that it will include the modified configuration.
 
-#udev_log="info"
+#udev_log=info
+#children_max=
+#exec_delay=
+#event_timeout=180
index c77ca57d933a3021a6823d597ffd7d2f99d828cf..9b316c80db1ade51904fe78ff48d9a07118d32f3 100644 (file)
@@ -1703,7 +1703,7 @@ int main(int argc, char *argv[]) {
         int r;
 
         log_set_target(LOG_TARGET_AUTO);
-        udev_parse_config();
+        udev_parse_config_full(&arg_children_max, &arg_exec_delay_usec, &arg_event_timeout_usec);
         log_parse_environment();
         log_open();