From: LiFeng Date: Tue, 5 Sep 2017 15:16:50 +0000 (+0800) Subject: console: clean tty state + return 0 on peer exit X-Git-Tag: lxc-2.0.9~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44a43f52b4297d5b20f3f83f9119d87ee5b5efa0;p=thirdparty%2Flxc.git console: clean tty state + return 0 on peer exit In the past, if the console client exited, lxc_console_cb_con return 1. And the lxc_poll will exit, the process will wait at waitpid. At this moment, the process could not handle any command (For example get the container state LXC_CMD_GET_STATE or stop the container LXC_CMD_STOP.). I think we should clean the tty_state and return 0 in this case. So, we can use the lxc-console to connect the console of the container. And we will not exit the function lxc_polland we can handle the commands by lxc_cmd_process Reproducer prior to this commit: - open a new terminal, get the tty device name by command tty /dev/pts/6 - set lxc.console.path = /dev/pts/6 - start the container and the ouptut will print to /dev/pts/6 - close /dev/pts/6 - try an operation e.g. getting state with lxc-ls and lxc-ls will hang Closes #1787. Signed-off-by: LiFeng Acked-by: Christian Brauner --- diff --git a/src/lxc/console.c b/src/lxc/console.c index 666754d27..97ae7a16e 100644 --- a/src/lxc/console.c +++ b/src/lxc/console.c @@ -174,6 +174,15 @@ static int lxc_console_cb_con(int fd, uint32_t events, void *data, if (r <= 0) { INFO("console client on fd %d has exited", fd); lxc_mainloop_del_handler(descr, fd); + if (fd == console->peer) { + if (console->tty_state) { + lxc_console_sigwinch_fini(console->tty_state); + console->tty_state = NULL; + } + console->peer = -1; + close(fd); + return 0; + } close(fd); return 1; }