Commit 9395937a by Christian Brauner

clean exit on EPOLLHUP

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: 's avatarChristian Brauner <christian.brauner@mailbox.org>
parent 39a78bbe
...@@ -22,27 +22,28 @@ ...@@ -22,27 +22,28 @@
*/ */
#include <assert.h> #include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <sys/epoll.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h> #include <sys/types.h>
#include <termios.h> #include <termios.h>
#include <unistd.h>
#include <lxc/lxccontainer.h> #include <lxc/lxccontainer.h>
#include "log.h" #include "af_unix.h"
#include "caps.h"
#include "commands.h"
#include "conf.h" #include "conf.h"
#include "config.h" #include "config.h"
#include "console.h" #include "console.h"
#include "start.h" /* for struct lxc_handler */ #include "log.h"
#include "caps.h"
#include "commands.h"
#include "mainloop.h"
#include "af_unix.h"
#include "lxclock.h" #include "lxclock.h"
#include "mainloop.h"
#include "start.h" /* for struct lxc_handler */
#include "utils.h" #include "utils.h"
#if HAVE_PTY_H #if HAVE_PTY_H
...@@ -630,6 +631,9 @@ int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata, ...@@ -630,6 +631,9 @@ int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata,
struct lxc_tty_state *ts = cbdata; struct lxc_tty_state *ts = cbdata;
char c; char c;
if (events & EPOLLHUP)
return 1;
assert(fd == ts->stdinfd); assert(fd == ts->stdinfd);
if (read(ts->stdinfd, &c, 1) < 0) { if (read(ts->stdinfd, &c, 1) < 0) {
SYSERROR("failed to read"); SYSERROR("failed to read");
...@@ -664,6 +668,9 @@ int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata, ...@@ -664,6 +668,9 @@ int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata,
char buf[1024]; char buf[1024];
int r, w; int r, w;
if (events & EPOLLHUP)
return 1;
assert(fd == ts->masterfd); assert(fd == ts->masterfd);
r = read(fd, buf, sizeof(buf)); r = read(fd, buf, sizeof(buf));
if (r < 0) { if (r < 0) {
......
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