From: Christian Brauner Date: Sun, 9 Aug 2020 16:55:52 +0000 (+0200) Subject: conf: make use of stashed container mountpoint fd in mount_autodev() X-Git-Tag: lxc-5.0.0~370^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae9215cfc06ce5cf940d423606cfdc4c4c91aa52;p=thirdparty%2Flxc.git conf: make use of stashed container mountpoint fd in mount_autodev() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index a15cd8283..2bf38c0e7 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -1051,7 +1051,6 @@ on_error: static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs, int autodevtmpfssize, const char *lxcpath) { - __do_close int root_mntpt_fd = -EBADF; const char *path = rootfs->path ? rootfs->mount : NULL; int ret; mode_t cur_mask; @@ -1062,19 +1061,15 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs, sprintf(mount_options, "size=%d,mode=755", (autodevtmpfssize != 0) ? autodevtmpfssize : 500000); DEBUG("Using mount options: %s", mount_options); - root_mntpt_fd = openat(-1, path, O_RDONLY | O_CLOEXEC | O_PATH | O_DIRECTORY); - if (root_mntpt_fd < 0) - return log_error_errno(-errno, errno, "Failed to open \"%s\"", path); - cur_mask = umask(S_IXUSR | S_IXGRP | S_IXOTH); - ret = mkdirat(root_mntpt_fd, "dev" , S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + ret = mkdirat(rootfs->mntpt_fd, "dev" , S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); if (ret < 0 && errno != EEXIST) { SYSERROR("Failed to create \"/dev\" directory"); ret = -errno; goto reset_umask; } - ret = safe_mount_beneath_at(root_mntpt_fd, "none", "dev", "tmpfs", 0, mount_options); + ret = safe_mount_beneath_at(rootfs->mntpt_fd, "none", "dev", "tmpfs", 0, mount_options); if (ret < 0) { __do_free char *fallback_path = NULL; @@ -1099,7 +1094,7 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs, /* If we are running on a devtmpfs mapping, dev/pts may already exist. * If not, then create it and exit if that fails... */ - ret = mkdirat(root_mntpt_fd, "dev/pts", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + ret = mkdirat(rootfs->mntpt_fd, "dev/pts", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); if (ret < 0 && errno != EEXIST) { SYSERROR("Failed to create directory \"%s\"", path); ret = -errno;