[lxc-devel] [lxc/master] lxc-attach: allow for situations without /dev/tty

brauner on Github lxc-bot at linuxcontainers.org
Fri May 12 14:34:43 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 381 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170512/e4bf4ca2/attachment.bin>
-------------- next part --------------
From f7056fe59787fbc132dfb353039f8b720e705dc2 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 12 May 2017 16:33:23 +0200
Subject: [PATCH] lxc-attach: allow for situations without /dev/tty

Closes #1552.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/console.c          |  2 +-
 src/lxc/tools/lxc_attach.c | 15 +++++++++++----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/lxc/console.c b/src/lxc/console.c
index 3baaed4..8eae7c4 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -441,7 +441,7 @@ static int lxc_console_peer_default(struct lxc_console *console)
 
 	console->peer = lxc_unpriv(open(path, O_CLOEXEC | O_RDWR | O_CREAT | O_APPEND, 0600));
 	if (console->peer < 0) {
-		ERROR("failed to open \"%s\"", path);
+		ERROR("failed to open \"%s\": %s", path, strerror(errno));
 		return -ENOTTY;
 	}
 	DEBUG("using \"%s\" as peer tty device", path);
diff --git a/src/lxc/tools/lxc_attach.c b/src/lxc/tools/lxc_attach.c
index c5e319f..a98e44c 100644
--- a/src/lxc/tools/lxc_attach.c
+++ b/src/lxc/tools/lxc_attach.c
@@ -279,7 +279,7 @@ static int get_pty_on_host_callback(void *p)
 
 static int get_pty_on_host(struct lxc_container *c, struct wrapargs *wrap, int *pid)
 {
-	int ret = -1;
+	int fd, ret = -1;
 	struct wrapargs *args = wrap;
 	struct lxc_epoll_descr descr;
 	struct lxc_conf *conf;
@@ -307,9 +307,16 @@ static int get_pty_on_host(struct lxc_container *c, struct wrapargs *wrap, int *
 	 * always do the correct thing. strdup() must be used since console.path
 	 * is free()ed when we call lxc_container_put(). */
 	free(conf->console.path);
-	conf->console.path = strdup("/dev/tty");
-	if (!conf->console.path)
-		return -1;
+	conf->console.path = NULL;
+	if (!access("/dev/tty", F_OK)) {
+		fd = open("/dev/tty", O_RDWR);
+		if (fd >= 0) {
+			close(fd);
+			conf->console.path = strdup("/dev/tty");
+			if (!conf->console.path)
+				return -1;
+		}
+	}
 
 	/* Create pty on the host. */
 	if (lxc_console_create(conf) < 0)


More information about the lxc-devel mailing list