]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevadm: wait: check if specified path not exist on --remove
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 22 Apr 2022 18:01:25 +0000 (03:01 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 22 Apr 2022 23:45:01 +0000 (08:45 +0900)
Even if the corresponding device node or syspath are already removed,
the specified symlink to the device node may still exist.

Fixes #23166.

src/udev/udevadm-wait.c

index 0ea0ed501ba9d8ed5e2012ec31acec108d62ba4a..29c8ee5cf4040d263d28bec0bb7e5674f5228958 100644 (file)
@@ -10,6 +10,7 @@
 #include "device-util.h"
 #include "errno-util.h"
 #include "fd-util.h"
+#include "fs-util.h"
 #include "inotify-util.h"
 #include "parse-util.h"
 #include "path-util.h"
@@ -48,22 +49,25 @@ static int check_device(const char *path) {
 
         assert(path);
 
+        if (arg_wait_until == WAIT_UNTIL_REMOVED) {
+                r = laccess(path, F_OK);
+                if (r == -ENOENT)
+                        return true;
+                if (r < 0)
+                        return r;
+                return false;
+        }
+
         r = sd_device_new_from_path(&dev, path);
         if (r == -ENODEV)
-                return arg_wait_until == WAIT_UNTIL_REMOVED;
+                return false;
         if (r < 0)
                 return r;
 
-        switch (arg_wait_until) {
-        case WAIT_UNTIL_INITIALIZED:
+        if (arg_wait_until == WAIT_UNTIL_INITIALIZED)
                 return sd_device_get_is_initialized(dev);
-        case WAIT_UNTIL_ADDED:
-                return true;
-        case WAIT_UNTIL_REMOVED:
-                return false;
-        default:
-                assert_not_reached();
-        }
+
+        return true;
 }
 
 static bool check(void) {