]> 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>
Wed, 29 Nov 2017 11:52:48 +0000 (12:52 +0100)
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.
Also, we should become session leader.

Closes #1646.
Closes #1951.

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

index 664dbc3baa73e7157ef763575553bda75273b695..9d148dae3e0e597ac3a2144e575f2e3cf6b3be77 100644 (file)
@@ -751,8 +751,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);
@@ -782,8 +787,11 @@ static int do_start(void *data)
 
        close(handler->sigfd);
 
-       /* after this call, we are in error because this
-        * ops should not return as it execs */
+       setsid();
+
+       /* After this call, we are in error because this ops should not return
+        * as it execs.
+        */
        handler->ops->start(handler, handler->data);
 
 out_warn_father: