diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c index c5bf8cdfe..5eee50625 100644 --- a/src/lxc/terminal.c +++ b/src/lxc/terminal.c @@ -334,7 +334,10 @@ static int lxc_terminal_ptx_io(struct lxc_terminal *terminal) w = r = lxc_read_nointr(terminal->ptx, buf, sizeof(buf)); if (r <= 0) - return -1; + if (errno == EWOULDBLOCK) + return 0; + else + return -1; w_rbuf = w_log = 0; /* write to peer first */ @@ -444,13 +447,21 @@ static int lxc_terminal_mainloop_add_peer(struct lxc_terminal *terminal) int lxc_terminal_mainloop_add(struct lxc_async_descr *descr, struct lxc_terminal *terminal) { - int ret; + int flags, ret; if (terminal->ptx < 0) { INFO("Terminal is not initialized"); return 0; } + flags = fcntl(terminal->ptx, F_GETFL); + flags |= O_NONBLOCK; + ret = fcntl(terminal->ptx, F_SETFL, flags); + if (ret < 0) { + ERROR("Failed to set O_NONBLOCK for terminal ptx fd %d", terminal->ptx); + return -1; + } + ret = lxc_mainloop_add_handler(descr, terminal->ptx, lxc_terminal_ptx_io_handler, default_cleanup_handler,