]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevadm-wait: let --removed override initialization
authordongshengyuan <545258830@qq.com>
Mon, 13 Jul 2026 02:36:10 +0000 (10:36 +0800)
committerdongshengyuan <545258830@qq.com>
Mon, 13 Jul 2026 04:18:49 +0000 (12:18 +0800)
The documentation says --initialized= is ignored when --removed is
specified.

Track --removed separately so it wins regardless of option order.

Reproducer:
  udevadm wait --timeout=0 --removed --initialized=no /dev/no-such-test-device

Before:
  Timed out for waiting devices being added.

Follow-up:
  aa2b0d8d291a1f1dc2b50016c076ff8196989f84

src/udev/udevadm-wait.c
test/units/TEST-17-UDEV.sanity-check.sh

index fa12e6c98c17c9e2c0b23d1607ef04fdfa8ee67b..08c142d5eb579d6d4b352118c2ce1052b702b40e 100644 (file)
@@ -32,6 +32,7 @@ typedef enum WaitUntil {
 
 static WaitUntil arg_wait_until = WAIT_UNTIL_INITIALIZED;
 static usec_t arg_timeout_usec = USEC_INFINITY;
+static bool arg_removed = false;
 static bool arg_settle = false;
 static char **arg_devices = NULL;
 
@@ -350,7 +351,7 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 OPTION_LONG("removed", NULL, "Wait for devices being removed"):
-                        arg_wait_until = WAIT_UNTIL_REMOVED;
+                        arg_removed = true;
                         break;
 
                 OPTION_LONG("settle", NULL, "Also wait for all queued events being processed"):
@@ -358,6 +359,9 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
                 }
 
+        if (arg_removed)
+                arg_wait_until = WAIT_UNTIL_REMOVED;
+
         char **args = option_parser_get_args(&opts);
         if (strv_isempty(args))
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
index 5fefa567499caf5101f7cb3cba707d211595e4c5..976408fef210092a1e3ec3fde7f10159bb33fca1 100755 (executable)
@@ -303,6 +303,9 @@ udevadm wait -t 5 /sys/class/net/$netdev
 udevadm wait --initialized true /sys/class/net/$netdev
 udevadm wait --initialized false /sys/class/net/$netdev
 (! udevadm wait --initialized hello /sys/class/net/$netdev)
+udevadm wait --timeout=0 --removed /dev/no-such-test-device
+udevadm wait --timeout=0 --removed --initialized=no /dev/no-such-test-device
+udevadm wait --timeout=0 --initialized=no --removed /dev/no-such-test-device
 assert_rc 124 timeout 5 udevadm wait --removed /sys/class/net/$netdev
 udevadm wait --settle /sys/class/net/$netdev
 udevadm wait -h