From: Li Feng Date: Mon, 10 Jul 2017 09:19:52 +0000 (+0800) Subject: start: dup std{in,out,err} to pty slave X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74941f9a3376e2a854ad449d1d65436013704e34;p=thirdparty%2Flxc.git start: dup std{in,out,err} to pty slave 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 Signed-off-by: Christian Brauner --- diff --git a/src/lxc/start.c b/src/lxc/start.c index 664dbc3ba..9d148dae3 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -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: