]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: restore udevadm settle timeout
authorNir Soffer <nirsof@gmail.com>
Wed, 8 Apr 2015 01:04:16 +0000 (04:04 +0300)
committerDavid Herrmann <dh.herrmann@gmail.com>
Sat, 11 Apr 2015 10:35:07 +0000 (12:35 +0200)
Commit 9ea28c55a2 (udev: remove seqnum API and all assumptions about
seqnums) introduced a regresion, ignoring the timeout option when
waiting until the event queue is empty.

Previously, if the udev event queue was not empty when the timeout was
expired, udevadm settle was returning with exit code 1.  To check if the
queue is empty, you could invoke udevadm settle with timeout=0. This
patch restores the previous behavior.

(David: fixed timeout==0 handling and dropped redundant assignment)

src/udev/udevadm-settle.c

index 0d3025ed16c809a3bfa6c3eafc8ff8d7c48fbb9b..2c84ada0b10c32257ef9fb6c6a5f4e82dcd44c59 100644 (file)
@@ -49,6 +49,7 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
                 { "quiet",          no_argument,       NULL, 'q' }, /* removed */
                 {}
         };
+        usec_t deadline;
         const char *exists = NULL;
         unsigned int timeout = 120;
         struct pollfd pfd[1] = { {.fd = -1}, };
@@ -98,6 +99,8 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
                 return EXIT_FAILURE;
         }
 
+        deadline = now(CLOCK_MONOTONIC) + timeout * USEC_PER_SEC;
+
         /* guarantee that the udev daemon isn't pre-processing */
         if (getuid() == 0) {
                 struct udev_ctrl *uctrl;
@@ -139,6 +142,9 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
                         break;
                 }
 
+                if (timeout > 0 && now(CLOCK_MONOTONIC) >= deadline)
+                        break;
+
                 /* wake up when queue is empty */
                 if (poll(pfd, 1, MSEC_PER_SEC) > 0 && pfd[0].revents & POLLIN)
                         udev_queue_flush(queue);