]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
start: dup std{in,out,err} to pty slave
authorLi Feng <lifeng68@huawei.com>
Mon, 10 Jul 2017 09:19:52 +0000 (17:19 +0800)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 10 Jul 2017 09:41:02 +0000 (11:41 +0200)
In the case the container has a console with a valid slave pty file descriptor
we duplicate std{in,out,err} to the slave file descriptor so console logging
works correctly. When the container does not have a valid slave pty file
descriptor for its console and is started daemonized we should dup to
/dev/null.

Closes #1646.

Signed-off-by: Li Feng <lifeng68@huawei.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/start.c

index 9a7e462d0b517e9c92b9a460086972d0131b807f..481776186a8d614f8c6c74e65012b27f9b090b97 100644 (file)
@@ -1063,8 +1063,13 @@ static int do_start(void *data)
         * setup on its console ie. the pty allocated in lxc_console_create() so
         * make sure that that pty is stdin,stdout,stderr.
         */
-       if (lxc_console_set_stdfds(handler->conf->console.slave) < 0)
-               goto out_warn_father;
+        if (handler->conf->console.slave >= 0)
+                if (set_stdfds(handler->conf->console.slave) < 0) {
+                       ERROR("Failed to redirect std{in,out,err} to pty file "
+                             "descriptor %d",
+                             handler->conf->console.slave);
+                       goto out_warn_father;
+                }
 
        /* If we mounted a temporary proc, then unmount it now. */
        tmp_proc_unmount(handler->conf);
@@ -1142,8 +1147,12 @@ static int do_start(void *data)
                        goto out_warn_father;
        }
 
-       if (handler->backgrounded && set_stdfds(devnull_fd))
-               goto out_warn_father;
+       if (handler->conf->console.slave < 0 && handler->backgrounded)
+               if (set_stdfds(devnull_fd) < 0) {
+                       ERROR("Failed to redirect std{in,out,err} to "
+                             "\"/dev/null\"");
+                       goto out_warn_father;
+               }
 
        if (devnull_fd >= 0) {
                close(devnull_fd);