Unverified Commit b4700e2c by Li Feng Committed by Stéphane Graber

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. 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: 's avatarLi Feng <lifeng68@huawei.com> Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent bad62acb
...@@ -1036,8 +1036,13 @@ static int do_start(void *data) ...@@ -1036,8 +1036,13 @@ static int do_start(void *data)
* setup on its console ie. the pty allocated in lxc_console_create() so * setup on its console ie. the pty allocated in lxc_console_create() so
* make sure that that pty is stdin,stdout,stderr. * make sure that that pty is stdin,stdout,stderr.
*/ */
if (lxc_console_set_stdfds(handler->conf->console.slave) < 0) if (handler->conf->console.slave >= 0)
goto out_warn_father; 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. */ /* If we mounted a temporary proc, then unmount it now. */
tmp_proc_unmount(handler->conf); tmp_proc_unmount(handler->conf);
...@@ -1115,8 +1120,12 @@ static int do_start(void *data) ...@@ -1115,8 +1120,12 @@ static int do_start(void *data)
goto out_warn_father; goto out_warn_father;
} }
if (handler->backgrounded && set_stdfds(devnull_fd)) if (handler->conf->console.slave < 0 && handler->backgrounded)
goto out_warn_father; 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) { if (devnull_fd >= 0) {
close(devnull_fd); close(devnull_fd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment