xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: "xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>
Subject: Re: [PATCH] libxl: check pending child signals on libxl__ev_child_inuse
Date: Tue, 10 Jul 2012 12:13:44 +0100	[thread overview]
Message-ID: <4FFC0E68.6020105@citrix.com> (raw)
In-Reply-To: <4FFACD0F.9060000@citrix.com>

Roger Pau Monne wrote:
> Roger Pau Monne wrote:
>> Since we might call libxl__ev_child_inuse from the callback of another
>> event, and we might have pending signals from dead processes, update
>> the processes status before returning to the caller.
>>
>> This was noticed because we processed POLLHUP before the child pipe,
>> so we ended up trying to kill the child process from the PULLHUP
>> callback, when the child was already dead. With this patch
>> libxl__ev_child_inuse returns false, and we no longer try to kill an
>> already dead child.
>
> This is not correct, since we might assert that the child is running
> after a fork, but if the execution time is very short it might be dead.
>
> A better solution might be to change the order in which events are
> processed, the following patch makes libxl process child events before
> anything else.
>
> 8<--------------------------------------------------------------------
>
> [PATCH] libxl: check child signals before other events
>
> Check pending signals from child processes before processing other
> events, since the callbacks for other events might check the status of
> the child and try to kill them, when they might already be dead.

Since this is also prone to races, we should ignore POLLHUP on 
datacopier_readable and wait for the underlying process (the bootloader 
in this case) to exit. Linux probably doesn't send a POLLHUP when the 
process on the other end of the pty dies, but NetBSD does so, and since 
we process the fd events first we should ignore this and expect that the 
process dies.

8<---------------------------------------------------------------------

Subject: [PATCH] libxl: react correctly to POLLHUP

On datacopier_readable ignore PULLHUP, since we will shortly process
the death of the underlying process.

Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
---
  tools/libxl/libxl_aoutils.c |    8 ++++++++
  1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/tools/libxl/libxl_aoutils.c b/tools/libxl/libxl_aoutils.c
index 99972a2..fa07154 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, "
+                   "waiting for process to die",
+                   dc->readwhat, dc->copywhat);
+        libxl__ev_fd_deregister(gc, &dc->toread);
+        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);
-- 
1.7.7.5 (Apple Git-26)

  reply	other threads:[~2012-07-10 11:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-09 11:54 [PATCH] libxl: check pending child signals on libxl__ev_child_inuse Roger Pau Monne
2012-07-09 12:22 ` Roger Pau Monne
2012-07-10 11:13   ` Roger Pau Monne [this message]
2012-07-17 14:27     ` Ian Jackson

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=4FFC0E68.6020105@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).