Commit 32bf1787 by Christian Brauner Committed by Stéphane Graber

use lxc_read_nointr() and lxc_write_nointr()

Using EPOLLHUP to determine when to exit the loop is unreliable. Let's exit clean when read() returns -1 && errno != EINTR or 0. Signed-off-by: 's avatarChristian Brauner <christian.brauner@mailbox.org>
parent d3e3b188
...@@ -161,33 +161,25 @@ static int lxc_console_cb_con(int fd, uint32_t events, void *data, ...@@ -161,33 +161,25 @@ static int lxc_console_cb_con(int fd, uint32_t events, void *data,
{ {
struct lxc_console *console = (struct lxc_console *)data; struct lxc_console *console = (struct lxc_console *)data;
char buf[1024]; char buf[1024];
int r,w; int r, w;
if (events & EPOLLHUP)
return 1;
w = r = read(fd, buf, sizeof(buf));
if (r < 0) {
SYSERROR("failed to read");
return 1;
}
if (!r) { w = r = lxc_read_nointr(fd, buf, sizeof(buf));
if (r <= 0) {
INFO("console client on fd %d has exited", fd); INFO("console client on fd %d has exited", fd);
lxc_mainloop_del_handler(descr, fd); lxc_mainloop_del_handler(descr, fd);
close(fd); close(fd);
return 0; return 1;
} }
if (fd == console->peer) if (fd == console->peer)
w = write(console->master, buf, r); w = lxc_write_nointr(console->master, buf, r);
if (fd == console->master) { if (fd == console->master) {
if (console->log_fd >= 0) if (console->log_fd >= 0)
w = write(console->log_fd, buf, r); w = lxc_write_nointr(console->log_fd, buf, r);
if (console->peer >= 0) if (console->peer >= 0)
w = write(console->peer, buf, r); w = lxc_write_nointr(console->peer, buf, r);
} }
if (w != r) if (w != r)
......
...@@ -301,8 +301,10 @@ static int get_pty_on_host(struct lxc_container *c, struct wrapargs *wrap, int * ...@@ -301,8 +301,10 @@ static int get_pty_on_host(struct lxc_container *c, struct wrapargs *wrap, int *
goto err2; goto err2;
} }
if (lxc_console_mainloop_add(&descr, conf) < 0) if (lxc_console_mainloop_add(&descr, conf) < 0) {
ERROR("Failed to add handlers to lxc mainloop.");
goto err3; goto err3;
}
ret = lxc_mainloop(&descr, -1); ret = lxc_mainloop(&descr, -1);
if (ret) { if (ret) {
......
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