From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xen.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>,
Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH v2 2/5] libxl: react correctly to POLLHUP
Date: Thu, 26 Jul 2012 20:54:33 +0100 [thread overview]
Message-ID: <1343332476-33765-3-git-send-email-roger.pau@citrix.com> (raw)
In-Reply-To: <1343332476-33765-1-git-send-email-roger.pau@citrix.com>
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@eu.citrix.com>
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
---
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)
next prev parent reply other threads:[~2012-07-26 19:54 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-26 19:54 [PATCH v2 0/5] NetBSD: minor fixes and hotplug execution Roger Pau Monne
2012-07-26 19:54 ` [PATCH v2 1/5] tools/build: fix pygrub linking Roger Pau Monne
2012-07-27 8:48 ` Ian Campbell
2012-08-01 11:47 ` Ian Campbell
2012-08-02 5:42 ` Olaf Hering
2012-08-02 6:44 ` Ian Campbell
2012-07-26 19:54 ` Roger Pau Monne [this message]
2012-07-27 8:53 ` [PATCH v2 2/5] libxl: react correctly to POLLHUP Ian Campbell
2012-07-27 14:26 ` Ian Jackson
2012-07-27 17:01 ` Ian Jackson
2012-07-31 13:18 ` Ian Campbell
2012-07-31 14:42 ` Ian Jackson
2012-07-27 14:27 ` Ian Jackson
2012-07-26 19:54 ` [PATCH v2 3/5] hotplug/NetBSD: check type of file to attach from params Roger Pau Monne
2012-07-27 14:28 ` Ian Jackson
2012-07-26 19:54 ` [PATCH v2 4/5] libxl: call hotplug scripts from xl for NetBSD Roger Pau Monne
2012-07-27 12:49 ` Christoph Egger
2012-08-01 11:47 ` Ian Campbell
2012-07-26 19:54 ` [PATCH v2 5/5] init/NetBSD: move xenbackendd to xend init script Roger Pau Monne
2012-07-27 12:50 ` Christoph Egger
2012-07-27 14:29 ` Ian Jackson
2012-07-27 14:49 ` Christoph Egger
2012-08-01 11:47 ` Ian Campbell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1343332476-33765-3-git-send-email-roger.pau@citrix.com \
--to=roger.pau@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).