[lxc-devel] [lxc/master] use lxc_read_nointr() and lxc_write_nointr()
brauner on Github
lxc-bot at linuxcontainers.org
Fri Apr 8 18:31:49 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 497 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160408/1117ac4c/attachment.bin>
-------------- next part --------------
From 3e6580ec3a22edccf9a211dcac40767727009ef1 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at mailbox.org>
Date: Fri, 8 Apr 2016 20:28:59 +0200
Subject: [PATCH] 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: Christian Brauner <christian.brauner at mailbox.org>
---
src/lxc/console.c | 22 +++++++---------------
src/lxc/lxc_attach.c | 4 +++-
2 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/src/lxc/console.c b/src/lxc/console.c
index f874172..a8d09ca 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -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;
char buf[1024];
- int r,w;
-
- if (events & EPOLLHUP)
- return 1;
-
- w = r = read(fd, buf, sizeof(buf));
- if (r < 0) {
- SYSERROR("failed to read");
- return 1;
- }
+ int r, w;
- if (!r) {
+ w = r = lxc_read_nointr(fd, buf, sizeof(buf));
+ if (r <= 0) {
INFO("console client on fd %d has exited", fd);
lxc_mainloop_del_handler(descr, fd);
close(fd);
- return 0;
+ return 1;
}
if (fd == console->peer)
- w = write(console->master, buf, r);
+ w = lxc_write_nointr(console->master, buf, r);
if (fd == console->master) {
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)
- w = write(console->peer, buf, r);
+ w = lxc_write_nointr(console->peer, buf, r);
}
if (w != r)
diff --git a/src/lxc/lxc_attach.c b/src/lxc/lxc_attach.c
index f02ef26..ed3ba0d 100644
--- a/src/lxc/lxc_attach.c
+++ b/src/lxc/lxc_attach.c
@@ -301,8 +301,10 @@ static int get_pty_on_host(struct lxc_container *c, struct wrapargs *wrap, int *
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;
+ }
ret = lxc_mainloop(&descr, -1);
if (ret) {
More information about the lxc-devel
mailing list