|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 2/5] libxl: react correctly to POLLHUP
When received POLLHUP on datacopier_readable/writable, kill the
datacopier and call the callback with onwrite=-2. On the bootloader
callback kill the bootloader process and wait for the callback, but
without setting the bl->rc error code.
This is because NetBSD returns POLLHUP when the process on the other
end of the pty exits (even when exiting normally).
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxx>
---
tools/libxl/libxl_aoutils.c | 16 ++++++++++++++++
tools/libxl/libxl_bootloader.c | 9 ++++++---
tools/libxl/libxl_internal.h | 1 +
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/tools/libxl/libxl_aoutils.c b/tools/libxl/libxl_aoutils.c
index 99972a2..2ea9b2c 100644
--- a/tools/libxl/libxl_aoutils.c
+++ b/tools/libxl/libxl_aoutils.c
@@ -102,6 +102,14 @@ static void datacopier_readable(libxl__egc *egc,
libxl__ev_fd *ev,
libxl__datacopier_state *dc = CONTAINER_OF(ev, *dc, toread);
STATE_AO_GC(dc->ao);
+ if (revents & POLLHUP) {
+ LOG(DEBUG, "received POLLHUP on %s during copy of %s, "
+ "killing the bootloader process",
+ dc->readwhat, dc->copywhat);
+ datacopier_callback(egc, dc, -2, 0);
+ return;
+ }
+
if (revents & ~POLLIN) {
LOG(ERROR, "unexpected poll event 0x%x (should be POLLIN)"
" on %s during copy of %s", revents, dc->readwhat, dc->copywhat);
@@ -163,6 +171,14 @@ static void datacopier_writable(libxl__egc *egc,
libxl__ev_fd *ev,
libxl__datacopier_state *dc = CONTAINER_OF(ev, *dc, towrite);
STATE_AO_GC(dc->ao);
+ if (revents & POLLHUP) {
+ LOG(DEBUG, "received POLLHUP on %s during copy of %s, "
+ "killing the bootloader process",
+ dc->writewhat, dc->copywhat);
+ datacopier_callback(egc, dc, -2, 0);
+ return;
+ }
+
if (revents & ~POLLOUT) {
LOG(ERROR, "unexpected poll event 0x%x (should be POLLOUT)"
" on %s during copy of %s", revents, dc->writewhat, dc->copywhat);
diff --git a/tools/libxl/libxl_bootloader.c b/tools/libxl/libxl_bootloader.c
index ef5a91b..f3d92e2 100644
--- a/tools/libxl/libxl_bootloader.c
+++ b/tools/libxl/libxl_bootloader.c
@@ -285,8 +285,8 @@ static void bootloader_abort(libxl__egc *egc,
libxl__datacopier_kill(&bl->display);
if (libxl__ev_child_inuse(&bl->child)) {
r = kill(bl->child.pid, SIGTERM);
- if (r) LOGE(WARN, "after failure, failed to kill bootloader [%lu]",
- (unsigned long)bl->child.pid);
+ if (r) LOGE(WARN, "%sfailed to kill bootloader [%lu]",
+ rc ? "after failure, " : "", (unsigned long)bl->child.pid);
}
bl->rc = rc;
}
@@ -567,7 +567,10 @@ static void bootloader_copyfail(libxl__egc *egc, const
char *which,
STATE_AO_GC(bl->ao);
if (!onwrite && !errnoval)
LOG(ERROR, "unexpected eof copying %s", which);
- bootloader_abort(egc, bl, ERROR_FAIL);
+ if (onwrite == -2)
+ bootloader_abort(egc, bl, 0);
+ else
+ bootloader_abort(egc, bl, ERROR_FAIL);
}
static void bootloader_keystrokes_copyfail(libxl__egc *egc,
libxl__datacopier_state *dc, int onwrite, int errnoval)
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 3ee3a09..286aa19 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -2073,6 +2073,7 @@ typedef struct libxl__datacopier_buf
libxl__datacopier_buf;
* errnoval==0 means we got eof and all data was written
* errnoval!=0 means we had a read error, logged
* onwrite==-1 means some other internal failure, errnoval not valid, logged
+ * onwrite==-2 means we got a POLLHUP, errnoval not valid, logged
* in all cases copier is killed before calling this callback */
typedef void libxl__datacopier_callback(libxl__egc *egc,
libxl__datacopier_state *dc, int onwrite, int errnoval);
--
1.7.7.5 (Apple Git-26)
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |