From: Christian Brauner Date: Wed, 3 Feb 2021 09:48:12 +0000 (+0100) Subject: conf: fd-only operations in lxc_setup_dev_symlinks() X-Git-Tag: lxc-5.0.0~303^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79019997c82c4a2337b0120b4bc8a0da950deb0e;p=thirdparty%2Flxc.git conf: fd-only operations in lxc_setup_dev_symlinks() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 0e17c93d7..bfbc98a20 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -781,31 +781,30 @@ static const struct dev_symlinks dev_symlinks[] = { static int lxc_setup_dev_symlinks(const struct lxc_rootfs *rootfs) { - int i, ret; - char path[PATH_MAX]; - struct stat s; - - for (i = 0; i < sizeof(dev_symlinks) / sizeof(dev_symlinks[0]); i++) { + for (int i = 0; i < sizeof(dev_symlinks) / sizeof(dev_symlinks[0]); i++) { + int ret; + struct stat s; const struct dev_symlinks *d = &dev_symlinks[i]; - ret = snprintf(path, sizeof(path), "%s/dev/%s", - rootfs->path ? rootfs->mount : "", d->name); - if (ret < 0 || (size_t)ret >= sizeof(path)) - return -1; - - /* Stat the path first. If we don't get an error accept it as + /* + * Stat the path first. If we don't get an error accept it as * 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) continue; - ret = symlink(d->oldpath, path); - if (ret && errno != EEXIST) { - if (errno == EROFS) - WARN("Failed to create \"%s\". Read-only filesystem", path); - else - return log_error_errno(-1, errno, "Failed to create \"%s\"", path); + ret = symlinkat(d->oldpath, rootfs->dev_mntpt_fd, d->name); + if (ret) { + switch (errno) { + case EROFS: + WARN("Failed to create \"%s\" on read-only filesystem", d->name); + __fallthrough; + case EEXIST: + break; + default: + return log_error_errno(-errno, errno, "Failed to create \"%s\"", d->name); + } } }