naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
923a60
From b2575f7d4f06ab9df5c5744e0324160effda437e Mon Sep 17 00:00:00 2001
923a60
From: Nir Soffer <nirsof@gmail.com>
923a60
Date: Wed, 8 Apr 2015 04:04:16 +0300
923a60
Subject: [PATCH] udev: restore udevadm settle timeout
923a60
923a60
Commit 9ea28c55a2 (udev: remove seqnum API and all assumptions about
923a60
seqnums) introduced a regresion, ignoring the timeout option when
923a60
waiting until the event queue is empty.
923a60
923a60
Previously, if the udev event queue was not empty when the timeout was
923a60
expired, udevadm settle was returning with exit code 1.  To check if the
923a60
queue is empty, you could invoke udevadm settle with timeout=0. This
923a60
patch restores the previous behavior.
923a60
923a60
(David: fixed timeout==0 handling and dropped redundant assignment)
923a60
923a60
Cherry-picked from: 0736455b1186c9515e0f093e1e686e684d225787
923a60
Resolves: #1210981
923a60
---
923a60
 src/udev/udevadm-settle.c | 6 ++++++
923a60
 1 file changed, 6 insertions(+)
923a60
923a60
diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c
923a60
index fff5de7a8b..e60c4623bd 100644
923a60
--- a/src/udev/udevadm-settle.c
923a60
+++ b/src/udev/udevadm-settle.c
923a60
@@ -56,6 +56,7 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
923a60
                 { "quiet",          no_argument,       NULL, 'q' }, /* removed */
923a60
                 {}
923a60
         };
923a60
+        usec_t deadline;
923a60
         const char *exists = NULL;
923a60
         unsigned int timeout = 120;
923a60
         struct pollfd pfd[1] = { {.fd = -1}, };
923a60
@@ -105,6 +106,8 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
923a60
                 return EXIT_FAILURE;
923a60
         }
923a60
 
923a60
+        deadline = now(CLOCK_MONOTONIC) + timeout * USEC_PER_SEC;
923a60
+
923a60
         /* guarantee that the udev daemon isn't pre-processing */
923a60
         if (getuid() == 0) {
923a60
                 struct udev_ctrl *uctrl;
923a60
@@ -146,6 +149,9 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
923a60
                         break;
923a60
                 }
923a60
 
923a60
+                if (timeout > 0 && now(CLOCK_MONOTONIC) >= deadline)
923a60
+                        break;
923a60
+
923a60
                 /* wake up when queue is empty */
923a60
                 if (poll(pfd, 1, MSEC_PER_SEC) > 0 && pfd[0].revents & POLLIN)
923a60
                         udev_queue_flush(queue);