conf: fd-only operations in lxc_setup_dev_symlinks()

parent 81498328
...@@ -781,31 +781,30 @@ static const struct dev_symlinks dev_symlinks[] = { ...@@ -781,31 +781,30 @@ static const struct dev_symlinks dev_symlinks[] = {
static int lxc_setup_dev_symlinks(const struct lxc_rootfs *rootfs) static int lxc_setup_dev_symlinks(const struct lxc_rootfs *rootfs)
{ {
int i, ret; for (int i = 0; i < sizeof(dev_symlinks) / sizeof(dev_symlinks[0]); i++) {
char path[PATH_MAX]; int ret;
struct stat s; struct stat s;
for (i = 0; i < sizeof(dev_symlinks) / sizeof(dev_symlinks[0]); i++) {
const struct dev_symlinks *d = &dev_symlinks[i]; const struct dev_symlinks *d = &dev_symlinks[i];
ret = snprintf(path, sizeof(path), "%s/dev/%s", /*
rootfs->path ? rootfs->mount : "", d->name); * Stat the path first. If we don't get an error accept it as
if (ret < 0 || (size_t)ret >= sizeof(path))
return -1;
/* Stat the path first. If we don't get an error accept it as
* is and don't try to create it * is and don't try to create it
*/ */
ret = stat(path, &s); ret = fstatat(rootfs->dev_mntpt_fd, d->name, &s, 0);
if (ret == 0) if (ret == 0)
continue; continue;
ret = symlink(d->oldpath, path); ret = symlinkat(d->oldpath, rootfs->dev_mntpt_fd, d->name);
if (ret && errno != EEXIST) { if (ret) {
if (errno == EROFS) switch (errno) {
WARN("Failed to create \"%s\". Read-only filesystem", path); case EROFS:
else WARN("Failed to create \"%s\" on read-only filesystem", d->name);
return log_error_errno(-1, errno, "Failed to create \"%s\"", path); __fallthrough;
case EEXIST:
break;
default:
return log_error_errno(-errno, errno, "Failed to create \"%s\"", d->name);
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment