daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
84b277
From 3f13db324c715ab9dd0a514490160448ed3ae7ee Mon Sep 17 00:00:00 2001
84b277
From: Hannes Reinecke <hare@suse.de>
84b277
Date: Tue, 29 Jul 2014 09:06:14 +0200
84b277
Subject: [PATCH] udevd: add --event-timeout commandline option
84b277
84b277
Some events take longer than the default 30 seconds. Killing those
84b277
events will leave the machine halfway configured.
84b277
84b277
Add a commandline option '--event-timeout' to handle these cases.
84b277
84b277
(cherry-picked from 9719859c07aa13539ed2cd4b31972cd30f678543)
84b277
84b277
Conflicts:
84b277
	src/udev/udevd.c
84b277
84b277
Resolves: #1154778
84b277
---
84b277
 man/systemd-udevd.service.xml | 19 +++++++++++++++++++
84b277
 src/udev/udevd.c              | 14 ++++++++++++--
84b277
 2 files changed, 31 insertions(+), 2 deletions(-)
84b277
84b277
diff --git a/man/systemd-udevd.service.xml b/man/systemd-udevd.service.xml
84b277
index 7fce300..c3a2cb9 100644
84b277
--- a/man/systemd-udevd.service.xml
84b277
+++ b/man/systemd-udevd.service.xml
84b277
@@ -42,6 +42,7 @@
84b277
       <arg><option>--debug</option></arg>
84b277
       <arg><option>--children-max=</option></arg>
84b277
       <arg><option>--exec-delay=</option></arg>
84b277
+      <arg><option>--event-timeout=</option></arg>
84b277
       <arg><option>--resolve-names=early|late|never</option></arg>
84b277
       <arg><option>--version</option></arg>
84b277
       <arg><option>--help</option></arg>
84b277
@@ -90,6 +91,15 @@
84b277
         </listitem>
84b277
       </varlistentry>
84b277
       <varlistentry>
84b277
+        <term><option>--event-timeout=</option></term>
84b277
+        <listitem>
84b277
+          <para>Wait for the event to finish up to the given
84b277
+          number of seconds. After this time the event will
84b277
+          be terminated. Default is 30.</para>
84b277
+        </listitem>
84b277
+      </varlistentry>
84b277
+
84b277
+      <varlistentry>
84b277
         <term><option>--resolve-names=</option></term>
84b277
         <listitem>
84b277
           <para>Specify when systemd-udevd should resolve names of users and groups.
84b277
@@ -155,6 +165,15 @@
84b277
         </listitem>
84b277
       </varlistentry>
84b277
       <varlistentry>
84b277
+        <term><varname>udev.event-timeout=</varname></term>
84b277
+        <term><varname>rd.udev.event-timeout=</varname></term>
84b277
+        <listitem>
84b277
+          <para>Wait for events to finish up to the given number
84b277
+          of seconds. This option might be useful if events are
84b277
+          terminated due to a timeout in large configurations.</para>
84b277
+        </listitem>
84b277
+      </varlistentry>
84b277
+      <varlistentry>
84b277
         <term><varname>net.ifnames=</varname></term>
84b277
         <listitem>
84b277
           <para>Network interfaces are renamed to give them predictable names
84b277
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
84b277
index 3d5feb4..6241549 100644
84b277
--- a/src/udev/udevd.c
84b277
+++ b/src/udev/udevd.c
84b277
@@ -72,6 +72,7 @@ static bool reload;
84b277
 static int children;
84b277
 static int children_max;
84b277
 static int exec_delay;
84b277
+static int event_timeout = 30;
84b277
 static sigset_t sigmask_orig;
84b277
 static UDEV_LIST(event_list);
84b277
 static UDEV_LIST(worker_list);
84b277
@@ -287,6 +288,9 @@ static void worker_new(struct event *event)
84b277
                         if (exec_delay > 0)
84b277
                                 udev_event->exec_delay = exec_delay;
84b277
 
84b277
+                        if (event_timeout != 30)
84b277
+                                udev_event->timeout_usec = event_timeout * USEC_PER_SEC;
84b277
+
84b277
                         /* apply rules, create node, symlinks */
84b277
                         udev_event_execute_rules(udev_event, rules, &sigmask_orig);
84b277
 
84b277
@@ -884,6 +888,8 @@ static void kernel_cmdline_options(struct udev *udev)
84b277
                         children_max = strtoul(opt + 18, NULL, 0);
84b277
                 } else if (startswith(opt, "udev.exec-delay=")) {
84b277
                         exec_delay = strtoul(opt + 16, NULL, 0);
84b277
+                } else if (startswith(opt, "udev.event-timeout=")) {
84b277
+                        event_timeout = strtoul(opt + 16, NULL, 0);
84b277
                 }
84b277
 
84b277
                 free(s);
84b277
@@ -903,6 +909,7 @@ int main(int argc, char *argv[])
84b277
                 { "debug", no_argument, NULL, 'D' },
84b277
                 { "children-max", required_argument, NULL, 'c' },
84b277
                 { "exec-delay", required_argument, NULL, 'e' },
84b277
+                { "event-timeout", required_argument, NULL, 't' },
84b277
                 { "resolve-names", required_argument, NULL, 'N' },
84b277
                 { "help", no_argument, NULL, 'h' },
84b277
                 { "version", no_argument, NULL, 'V' },
84b277
@@ -946,6 +953,9 @@ int main(int argc, char *argv[])
84b277
                 case 'e':
84b277
                         exec_delay = strtoul(optarg, NULL, 0);
84b277
                         break;
84b277
+                case 't':
84b277
+                        event_timeout = strtoul(optarg, NULL, 0);
84b277
+                        break;
84b277
                 case 'D':
84b277
                         debug = true;
84b277
                         log_set_max_level(LOG_DEBUG);
84b277
@@ -1278,8 +1288,8 @@ int main(int argc, char *argv[])
84b277
                                 if (worker->state != WORKER_RUNNING)
84b277
                                         continue;
84b277
 
84b277
-                                if ((now(CLOCK_MONOTONIC) - worker->event_start_usec) > 30 * 1000 * 1000) {
84b277
-                                        log_error("worker [%u] %s timeout; kill it\n", worker->pid,
84b277
+                                if ((now(CLOCK_MONOTONIC) - worker->event_start_usec) > event_timeout * USEC_PER_SEC) {
84b277
+                                        log_error("worker [%u] %s timeout; kill it", worker->pid,
84b277
                                             worker->event ? worker->event->devpath : "<idle>");
84b277
                                         kill(worker->pid, SIGKILL);
84b277
                                         worker->state = WORKER_KILLED;