]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: link_update() should fail if the entry in symlink dir couldn't have been created
authorFranck Bui <fbui@suse.com>
Wed, 9 Dec 2020 08:46:08 +0000 (09:46 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 9 Dec 2020 20:08:53 +0000 (21:08 +0100)
Follow-up for 30f6dce62cb3a738b20253f2192270607c31b55b

src/udev/udev-node.c

index bde18f756e446695f882a56eee9fad186a53d533..2cc78c9e2f4294d0d1b91c1364671d55182f182c 100644 (file)
@@ -214,20 +214,23 @@ static int link_update(sd_device *dev, const char *slink, bool add) {
         if (!filename)
                 return log_oom();
 
-        if (!add && unlink(filename) == 0)
-                (void) rmdir(dirname);
-
-        if (add)
-                do {
+        if (!add) {
+                if (unlink(filename) == 0)
+                        (void) rmdir(dirname);
+        } else
+                for (;;) {
                         _cleanup_close_ int fd = -1;
 
                         r = mkdir_parents(filename, 0755);
                         if (!IN_SET(r, 0, -ENOENT))
-                                break;
+                                return r;
+
                         fd = open(filename, O_WRONLY|O_CREAT|O_CLOEXEC|O_TRUNC|O_NOFOLLOW, 0444);
-                        if (fd < 0)
-                                r = -errno;
-                } while (r == -ENOENT);
+                        if (fd >= 0)
+                                break;
+                        if (errno != ENOENT)
+                                return -errno;
+                }
 
         /* If the database entry is not written yet we will just do one iteration and possibly wrong symlink
          * will be fixed in the second invocation. */