From: Christian Brauner Date: Fri, 16 Feb 2018 23:04:30 +0000 (+0100) Subject: console: ensure that fd is marked EBADF X-Git-Tag: lxc-2.0.10~325 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84bdd46000f8452857efc6acd1af4a512f122b7c;p=thirdparty%2Flxc.git console: ensure that fd is marked EBADF If the handler closes the file descriptor for the peer or master fd it is crucial that we mark it as -EBADF. This will prevent lxc_console_delete() from calling close() on an already closed file descriptor again. I've observed the double close in the attach code. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/console.c b/src/lxc/console.c index c233d9bd8..d928122fd 100644 --- a/src/lxc/console.c +++ b/src/lxc/console.c @@ -215,16 +215,20 @@ 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 (fd == console->master) { + console->master = -EBADF; + } else if (fd == console->peer) { if (console->tty_state) { lxc_console_signal_fini(console->tty_state); console->tty_state = NULL; } - console->peer = -1; - close(fd); - return 0; + console->peer = -EBADF; + } else { + ERROR("Handler received unexpected file descriptor"); } close(fd); + return LXC_MAINLOOP_CLOSE; }