]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-node: check stack directory change even if devlink is removed
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 1 Sep 2021 00:44:26 +0000 (09:44 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 2 Sep 2021 00:06:24 +0000 (09:06 +0900)
Otherwise, when multiple device additions and removals occur
simultaneously, symlink to unexisting devnode may be created.

Hopefully fixes #19946.

src/udev/udev-node.c

index 46c04fe00b9a9b7ca617f9134353292054d7ca9e..28e6e8df944695fd092f36a58b0c956bcf4ebc09 100644 (file)
@@ -468,15 +468,12 @@ static int link_update(sd_device *dev, const char *slink_in, bool add) {
                 if (r < 0)
                         return r;
 
-                /* Skip the second stat() if the first failed, stat_inode_unmodified() would return false regardless. */
-                if ((st1.st_mode & S_IFMT) != 0) {
-                        r = stat(dirname, &st2);
-                        if (r < 0 && errno != ENOENT)
-                                return log_device_debug_errno(dev, errno, "Failed to stat %s: %m", dirname);
-
-                        if (stat_inode_unmodified(&st1, &st2))
-                                break;
-                }
+                if (stat(dirname, &st2) < 0 && errno != ENOENT)
+                        return log_device_debug_errno(dev, errno, "Failed to stat %s: %m", dirname);
+
+                if (((st1.st_mode & S_IFMT) == 0 && (st2.st_mode & S_IFMT) == 0) ||
+                    stat_inode_unmodified(&st1, &st2))
+                        return 0;
         }
 
         return i < LINK_UPDATE_MAX_RETRIES ? 0 : -ELOOP;