From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roger Pau Monne Subject: Re: [PATCH] libxl: check pending child signals on libxl__ev_child_inuse Date: Tue, 10 Jul 2012 12:13:44 +0100 Message-ID: <4FFC0E68.6020105@citrix.com> References: <1341834859-57936-1-git-send-email-roger.pau@citrix.com> <4FFACD0F.9060000@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4FFACD0F.9060000@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: "xen-devel@lists.xen.org" Cc: Ian Jackson List-Id: xen-devel@lists.xenproject.org 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 Signed-off-by: Roger Pau Monne --- 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)