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: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 0d0d3655
......@@ -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;
}
......
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