[lxc-devel] [lxc/master] console: only create detached mount when a console is requested

brauner on Github lxc-bot at linuxcontainers.org
Thu May 14 13:53:42 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 404 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200514/4906c9f7/attachment.bin>
-------------- next part --------------
From 661e7671a2f21115c5a7198d9a1abaaa2bc7e62b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 14 May 2020 15:52:39 +0200
Subject: [PATCH] console: only create detached mount when a console is
 requested

otherwise weird things might happen.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/conf.c     | 16 +++++++++-------
 src/lxc/terminal.h |  8 ++++++++
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 3753fd7a62..76c10dc374 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -1583,7 +1583,7 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
 	char path[PATH_MAX];
 	char *rootfs_path = rootfs->path ? rootfs->mount : "";
 
-	if (console->path && !strcmp(console->path, "none"))
+	if (!lxc_terminal_path(console))
 		return 0;
 
 	ret = snprintf(path, sizeof(path), "%s/dev/console", rootfs_path);
@@ -1633,7 +1633,7 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
 	char path[PATH_MAX], lxcpath[PATH_MAX];
 	char *rootfs_path = rootfs->path ? rootfs->mount : "";
 
-	if (console->path && !strcmp(console->path, "none"))
+	if (!lxc_terminal_path(console))
 		return 0;
 
 	/* create rootfs/dev/<ttydir> directory */
@@ -3316,11 +3316,13 @@ int lxc_setup(struct lxc_handler *handler)
 			return log_error(-1, "Failed to send network device names and ifindices to parent");
 	}
 
-	pts_mnt_fd = open_tree(-EBADF, lxc_conf->console.name,
-			       OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC | AT_EMPTY_PATH);
-	if (pts_mnt_fd < 0)
-		SYSTRACE("Failed to create detached mount for container's console \"%s\"",
-			 lxc_conf->console.name);
+	if (lxc_terminal_path(&lxc_conf->console)) {
+		pts_mnt_fd = open_tree(-EBADF, lxc_conf->console.name,
+				       OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC | AT_EMPTY_PATH);
+		if (pts_mnt_fd < 0)
+			SYSTRACE("Failed to create detached mount for container's console \"%s\"",
+				 lxc_conf->console.name);
+	}
 
 	if (lxc_conf->autodev > 0) {
 		ret = mount_autodev(name, &lxc_conf->rootfs, lxc_conf->autodevtmpfssize, lxcpath);
diff --git a/src/lxc/terminal.h b/src/lxc/terminal.h
index 1283cb3377..aa99c27eeb 100644
--- a/src/lxc/terminal.h
+++ b/src/lxc/terminal.h
@@ -254,4 +254,12 @@ extern void lxc_terminal_init(struct lxc_terminal *terminal);
 extern int lxc_terminal_map_ids(struct lxc_conf *c,
 				struct lxc_terminal *terminal);
 
+static inline const char *lxc_terminal_path(const struct lxc_terminal *terminal)
+{
+	if (terminal->path && strcmp(terminal->path, "none"))
+		return terminal->path;
+
+	return NULL;
+}
+
 #endif /* __LXC_TERMINAL_H */


More information about the lxc-devel mailing list