]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
clean exit on EPOLLHUP
authorChristian Brauner <christian.brauner@mailbox.org>
Thu, 18 Feb 2016 14:20:34 +0000 (15:20 +0100)
committerChristian Brauner <christian.brauner@mailbox.org>
Sun, 21 Feb 2016 16:04:44 +0000 (17:04 +0100)
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>
src/lxc/console.c

index bdbc20b150253eae6ac0e0814f5015e6aea39f1f..e0f23586a16e03aa6b87b2f41b0c3b9c274e18b3 100644 (file)
  */
 
 #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
@@ -630,6 +631,9 @@ int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata,
        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");
@@ -664,6 +668,9 @@ int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata,
        char buf[1024];
        int r, w;
 
+       if (events & EPOLLHUP)
+               return 1;
+
        assert(fd == ts->masterfd);
        r = read(fd, buf, sizeof(buf));
        if (r < 0) {