The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/1553

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Closes #1552.

Signed-off-by: Christian Brauner <[email protected]>
From f7056fe59787fbc132dfb353039f8b720e705dc2 Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
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 <[email protected]>
---
 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)
_______________________________________________
lxc-devel mailing list
[email protected]
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to