udev: link_update() should fail if the entry in symlink dir couldn't have been created
Follow-up for 30f6dce62c
This commit is contained in:
parent
5e3effb1f3
commit
4e1db59274
|
@ -214,20 +214,23 @@ static int link_update(sd_device *dev, const char *slink, bool add) {
|
||||||
if (!filename)
|
if (!filename)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
|
||||||
if (!add && unlink(filename) == 0)
|
if (!add) {
|
||||||
(void) rmdir(dirname);
|
if (unlink(filename) == 0)
|
||||||
|
(void) rmdir(dirname);
|
||||||
if (add)
|
} else
|
||||||
do {
|
for (;;) {
|
||||||
_cleanup_close_ int fd = -1;
|
_cleanup_close_ int fd = -1;
|
||||||
|
|
||||||
r = mkdir_parents(filename, 0755);
|
r = mkdir_parents(filename, 0755);
|
||||||
if (!IN_SET(r, 0, -ENOENT))
|
if (!IN_SET(r, 0, -ENOENT))
|
||||||
break;
|
return r;
|
||||||
|
|
||||||
fd = open(filename, O_WRONLY|O_CREAT|O_CLOEXEC|O_TRUNC|O_NOFOLLOW, 0444);
|
fd = open(filename, O_WRONLY|O_CREAT|O_CLOEXEC|O_TRUNC|O_NOFOLLOW, 0444);
|
||||||
if (fd < 0)
|
if (fd >= 0)
|
||||||
r = -errno;
|
break;
|
||||||
} while (r == -ENOENT);
|
if (errno != ENOENT)
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
/* If the database entry is not written yet we will just do one iteration and possibly wrong symlink
|
/* 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. */
|
* will be fixed in the second invocation. */
|
||||||
|
|
Loading…
Reference in New Issue