summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranck Bui <fbui@suse.com>2020-12-09 09:46:08 +0100
committerLennart Poettering <lennart@poettering.net>2020-12-09 21:08:53 +0100
commit4e1db59274c4b31ba5369270a489420245616eb4 (patch)
tree8dfeb1cced408a4cd7a33ec1a37c6855d4f73375
parent5e3effb1f3327d531c8b9f45153ccec4313e4f6f (diff)
downloadsystemd-4e1db59274c4b31ba5369270a489420245616eb4.tar.gz
udev: link_update() should fail if the entry in symlink dir couldn't have been created
Follow-up for 30f6dce62cb3a738b20253f2192270607c31b55b
-rw-r--r--src/udev/udev-node.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c
index bde18f756e..2cc78c9e2f 100644
--- a/src/udev/udev-node.c
+++ b/src/udev/udev-node.c
@@ -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. */