teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0027-udev-node-check-stack-directory-change-even-if-devli.patch

4295f9
From 6ecd6fdcc27f374debcce47366c2862967f99463 Mon Sep 17 00:00:00 2001
4295f9
From: Yu Watanabe <watanabe.yu+github@gmail.com>
4295f9
Date: Wed, 1 Sep 2021 09:44:26 +0900
4295f9
Subject: [PATCH] udev-node: check stack directory change even if devlink is
4295f9
 removed
4295f9
4295f9
Otherwise, when multiple device additions and removals occur
4295f9
simultaneously, symlink to unexisting devnode may be created.
4295f9
4295f9
Hopefully fixes #19946.
4295f9
4295f9
(cherry picked from commit 1cd4e325693007b3628f1a27297f0ab7114b24b8)
4295f9
4295f9
Related: #1977994
4295f9
---
4295f9
 src/udev/udev-node.c | 15 ++++++---------
4295f9
 1 file changed, 6 insertions(+), 9 deletions(-)
4295f9
4295f9
diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c
4295f9
index 46c04fe00b..28e6e8df94 100644
4295f9
--- a/src/udev/udev-node.c
4295f9
+++ b/src/udev/udev-node.c
4295f9
@@ -468,15 +468,12 @@ static int link_update(sd_device *dev, const char *slink_in, bool add) {
4295f9
                 if (r < 0)
4295f9
                         return r;
4295f9
 
4295f9
-                /* Skip the second stat() if the first failed, stat_inode_unmodified() would return false regardless. */
4295f9
-                if ((st1.st_mode & S_IFMT) != 0) {
4295f9
-                        r = stat(dirname, &st2;;
4295f9
-                        if (r < 0 && errno != ENOENT)
4295f9
-                                return log_device_debug_errno(dev, errno, "Failed to stat %s: %m", dirname);
4295f9
-
4295f9
-                        if (stat_inode_unmodified(&st1, &st2))
4295f9
-                                break;
4295f9
-                }
4295f9
+                if (stat(dirname, &st2) < 0 && errno != ENOENT)
4295f9
+                        return log_device_debug_errno(dev, errno, "Failed to stat %s: %m", dirname);
4295f9
+
4295f9
+                if (((st1.st_mode & S_IFMT) == 0 && (st2.st_mode & S_IFMT) == 0) ||
4295f9
+                    stat_inode_unmodified(&st1, &st2))
4295f9
+                        return 0;
4295f9
         }
4295f9
 
4295f9
         return i < LINK_UPDATE_MAX_RETRIES ? 0 : -ELOOP;