From: dongshengyuan <545258830@qq.com> Date: Mon, 13 Jul 2026 02:36:10 +0000 (+0800) Subject: udevadm-wait: let --removed override initialization X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7bd6b8c5878cca9631b1ebbf93d9c79acaa5c586;p=thirdparty%2Fsystemd.git udevadm-wait: let --removed override initialization 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 --- diff --git a/src/udev/udevadm-wait.c b/src/udev/udevadm-wait.c index fa12e6c98c1..08c142d5eb5 100644 --- a/src/udev/udevadm-wait.c +++ b/src/udev/udevadm-wait.c @@ -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), diff --git a/test/units/TEST-17-UDEV.sanity-check.sh b/test/units/TEST-17-UDEV.sanity-check.sh index 5fefa567499..976408fef21 100755 --- a/test/units/TEST-17-UDEV.sanity-check.sh +++ b/test/units/TEST-17-UDEV.sanity-check.sh @@ -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