From: Christian Brauner Date: Fri, 30 Jul 2021 07:20:22 +0000 (+0200) Subject: conf: use mount_fd() helper when mounting ttys X-Git-Tag: lxc-5.0.0~127^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84f8f9e470bd76614a7f3d6ca2329d99d98bdfb4;p=thirdparty%2Flxc.git conf: use mount_fd() helper when mounting ttys Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 78f59e24a..4e0398097 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -961,7 +961,6 @@ static int lxc_setup_ttys(struct lxc_conf *conf) struct lxc_rootfs *rootfs = &conf->rootfs; const struct lxc_tty_info *ttys = &conf->ttys; char *ttydir = ttys->dir; - char tty_source[LXC_PROC_PID_FD_LEN], tty_target[LXC_PROC_PID_FD_LEN]; if (!conf->rootfs.path) return 0; @@ -994,7 +993,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf) "Failed to unlink %d(%s)", rootfs->dfd_dev, tty_name); - if (can_use_mount_api()) { + if (can_use_mount_api()) ret = fd_bind_mount(tty->pty, "", PROTECT_OPATH_FILE, PROTECT_LOOKUP_BENEATH_XDEV, @@ -1002,17 +1001,8 @@ static int lxc_setup_ttys(struct lxc_conf *conf) PROTECT_OPATH_FILE, PROTECT_LOOKUP_BENEATH_XDEV, 0, false); - } else { - ret = strnprintf(tty_source, sizeof(tty_source), "/proc/self/fd/%d", tty->pty); - if (ret < 0) - return ret; - - ret = strnprintf(tty_target, sizeof(tty_target), "/proc/self/fd/%d", fd_to); - if (ret < 0) - return ret; - - ret = mount(tty_source, tty_target, "none", MS_BIND, 0); - } + else + ret = mount_fd(tty->pty, fd_to, "none", MS_BIND, 0); if (ret < 0) return log_error_errno(-errno, errno, "Failed to bind mount \"%s\" onto \"%s\"", @@ -1037,7 +1027,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf) "Failed to create tty mount target %d(%s)", rootfs->dfd_dev, rootfs->buf); - if (can_use_mount_api()) { + if (can_use_mount_api()) ret = fd_bind_mount(tty->pty, "", PROTECT_OPATH_FILE, PROTECT_LOOKUP_BENEATH_XDEV, @@ -1045,17 +1035,8 @@ static int lxc_setup_ttys(struct lxc_conf *conf) PROTECT_OPATH_FILE, PROTECT_LOOKUP_BENEATH, 0, false); - } else { - ret = strnprintf(tty_source, sizeof(tty_source), "/proc/self/fd/%d", tty->pty); - if (ret < 0) - return ret; - - ret = strnprintf(tty_target, sizeof(tty_target), "/proc/self/fd/%d", fd_to); - if (ret < 0) - return ret; - - ret = mount(tty_source, tty_target, "none", MS_BIND, 0); - } + else + ret = mount_fd(tty->pty, fd_to, "none", MS_BIND, 0); if (ret < 0) return log_error_errno(-errno, errno, "Failed to bind mount \"%s\" onto \"%s\"",