lxc_console_cb_tty_masterfd() unnecessarily reported a read/write error when
the fd was closed. This happens e.g. when we have allocated a tty in the
container with lxc-console and we shut the container down. lxc-console will
then exit with an error message. This patch introduces a test whether the
EPOLLHUP bit is set in the events mask. If so, we report no error.
Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
*/
#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
+#include <sys/epoll.h>
#include <sys/types.h>
#include <termios.h>
+#include <unistd.h>
#include <lxc/lxccontainer.h>
-#include "log.h"
+#include "af_unix.h"
+#include "caps.h"
+#include "commands.h"
#include "conf.h"
#include "config.h"
#include "console.h"
-#include "start.h" /* for struct lxc_handler */
-#include "caps.h"
-#include "commands.h"
-#include "mainloop.h"
-#include "af_unix.h"
+#include "log.h"
#include "lxclock.h"
+#include "mainloop.h"
+#include "start.h" /* for struct lxc_handler */
#include "utils.h"
#if HAVE_PTY_H
struct lxc_tty_state *ts = cbdata;
char c;
+ if (events & EPOLLHUP)
+ return 1;
+
assert(fd == ts->stdinfd);
if (read(ts->stdinfd, &c, 1) < 0) {
SYSERROR("failed to read");
char buf[1024];
int r, w;
+ if (events & EPOLLHUP)
+ return 1;
+
assert(fd == ts->masterfd);
r = read(fd, buf, sizeof(buf));
if (r < 0) {