mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
break loops if util_create_path() returns error
Dangling symlinks in path components return -ENOENT. Do not retry to create the file in a loop in such case.
This commit is contained in:
parent
d316d27c17
commit
6834a44299
@ -410,13 +410,15 @@ static void update_failed(struct udev_queue_export *udev_queue_export,
|
||||
/* record event in the failed directory */
|
||||
udev_queue_export->failed_count++;
|
||||
do {
|
||||
util_create_path(udev, filename);
|
||||
err = util_create_path(udev, filename);
|
||||
if (err != 0 && err != -ENOENT)
|
||||
break;
|
||||
udev_selinux_setfscreatecon(udev, filename, S_IFLNK);
|
||||
err = symlink(udev_device_get_devpath(udev_device), filename);
|
||||
if (err != 0)
|
||||
err = errno;
|
||||
err = -errno;
|
||||
udev_selinux_resetfscreatecon(udev);
|
||||
} while (err == ENOENT);
|
||||
} while (err == -ENOENT);
|
||||
break;
|
||||
|
||||
case DEVICE_QUEUED:
|
||||
|
@ -43,18 +43,29 @@ int util_create_path(struct udev *udev, const char *path)
|
||||
pos[0] = '\0';
|
||||
|
||||
dbg(udev, "stat '%s'\n", p);
|
||||
if (stat(p, &stats) == 0 && (stats.st_mode & S_IFMT) == S_IFDIR)
|
||||
return 0;
|
||||
if (stat(p, &stats) == 0) {
|
||||
if ((stats.st_mode & S_IFMT) == S_IFDIR)
|
||||
return 0;
|
||||
else
|
||||
return -ENOTDIR;
|
||||
}
|
||||
|
||||
if (util_create_path(udev, p) != 0)
|
||||
return -1;
|
||||
err = util_create_path(udev, p);
|
||||
if (err != 0)
|
||||
return err;
|
||||
|
||||
dbg(udev, "mkdir '%s'\n", p);
|
||||
udev_selinux_setfscreatecon(udev, p, S_IFDIR|0755);
|
||||
err = mkdir(p, 0755);
|
||||
if (err != 0 && errno == EEXIST)
|
||||
if (stat(p, &stats) == 0 && (stats.st_mode & S_IFMT) == S_IFDIR)
|
||||
err = 0;
|
||||
if (err != 0) {
|
||||
err = -errno;
|
||||
if (err == -EEXIST && stat(p, &stats) == 0) {
|
||||
if ((stats.st_mode & S_IFMT) == S_IFDIR)
|
||||
err = 0;
|
||||
else
|
||||
err = -ENOTDIR;
|
||||
}
|
||||
}
|
||||
udev_selinux_resetfscreatecon(udev);
|
||||
return err;
|
||||
}
|
||||
|
@ -78,13 +78,15 @@ int udev_node_mknod(struct udev_device *dev, const char *file, dev_t devnum, mod
|
||||
} else {
|
||||
info(udev, "mknod(%s, %#o, (%u,%u))\n", file, mode, major(devnum), minor(devnum));
|
||||
do {
|
||||
util_create_path(udev, file);
|
||||
err = util_create_path(udev, file);
|
||||
if (err != 0 && err != -ENOENT)
|
||||
break;
|
||||
udev_selinux_setfscreatecon(udev, file, mode);
|
||||
err = mknod(file, mode, devnum);
|
||||
if (err != 0)
|
||||
err = errno;
|
||||
err = -errno;
|
||||
udev_selinux_resetfscreatecon(udev);
|
||||
} while (err == ENOENT);
|
||||
} while (err == -ENOENT);
|
||||
if (err != 0) {
|
||||
err(udev, "mknod(%s, %#o, (%u,%u) failed: %m\n", file, mode, major(devnum), minor(devnum));
|
||||
goto exit;
|
||||
@ -180,13 +182,15 @@ static int node_symlink(struct udev *udev, const char *node, const char *slink)
|
||||
} else {
|
||||
info(udev, "creating symlink '%s' to '%s'\n", slink, target);
|
||||
do {
|
||||
util_create_path(udev, slink);
|
||||
err = util_create_path(udev, slink);
|
||||
if (err != 0 && err != -ENOENT)
|
||||
break;
|
||||
udev_selinux_setfscreatecon(udev, slink, S_IFLNK);
|
||||
err = symlink(target, slink);
|
||||
if (err != 0)
|
||||
err = errno;
|
||||
err = -errno;
|
||||
udev_selinux_resetfscreatecon(udev);
|
||||
} while (err == ENOENT);
|
||||
} while (err == -ENOENT);
|
||||
if (err == 0)
|
||||
goto exit;
|
||||
}
|
||||
@ -195,13 +199,15 @@ static int node_symlink(struct udev *udev, const char *node, const char *slink)
|
||||
util_strscpyl(slink_tmp, sizeof(slink_tmp), slink, TMP_FILE_EXT, NULL);
|
||||
unlink(slink_tmp);
|
||||
do {
|
||||
util_create_path(udev, slink);
|
||||
udev_selinux_setfscreatecon(udev, slink, S_IFLNK);
|
||||
err = util_create_path(udev, slink_tmp);
|
||||
if (err != 0 && err != -ENOENT)
|
||||
break;
|
||||
udev_selinux_setfscreatecon(udev, slink_tmp, S_IFLNK);
|
||||
err = symlink(target, slink_tmp);
|
||||
if (err != 0)
|
||||
err = errno;
|
||||
err = -errno;
|
||||
udev_selinux_resetfscreatecon(udev);
|
||||
} while (err == ENOENT);
|
||||
} while (err == -ENOENT);
|
||||
if (err != 0) {
|
||||
err(udev, "symlink(%s, %s) failed: %m\n", target, slink_tmp);
|
||||
goto exit;
|
||||
@ -313,11 +319,17 @@ static void link_update(struct udev_device *dev, const char *slink, bool add)
|
||||
}
|
||||
|
||||
if (add) {
|
||||
int err;
|
||||
|
||||
dbg(udev, "creating index: '%s'\n", filename);
|
||||
do {
|
||||
util_create_path(udev, filename);
|
||||
symlink(udev_device_get_devpath(dev), filename);
|
||||
} while (errno == ENOENT);
|
||||
err = util_create_path(udev, filename);
|
||||
if (err != 0 && err != -ENOENT)
|
||||
break;
|
||||
err = symlink(udev_device_get_devpath(dev), filename);
|
||||
if (err != 0)
|
||||
err = -errno;
|
||||
} while (err == -ENOENT);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user