From: Ian Campbell Subject: Re: [PATCH 01/20] libxl: handle POLLERR, POLLHUP, POLLNVAL properly Date: Mon, 16 Apr 2012 08:53:13 +0100 Message-ID: <1334562793.4445.18.camel@dagon.hellion.org.uk> References: <1334342414-10289-1-git-send-email-ian.jackson@eu.citrix.com> <1334342414-10289-2-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1334342414-10289-2-git-send-email-ian.jackson@eu.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: Ian Jackson Cc: "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org On Fri, 2012-04-13 at 19:39 +0100, Ian Jackson wrote: > Pass POLLERR and POLLHUP to fd callbacks, as is necessary. > Crash on POLLNVAL since that means our fds are messed up. > > Document the behaviour (including the fact that poll sometimes sets > POLLHUP or POLLERR even if only POLLIN was requested. > > Fix the one current fd callback to do something with POLLERR|POLLHUP. > > Signed-off-by: Ian Jackson Acked-by: Ian Campbell > --- > tools/libxl/libxl_event.c | 7 ++++++- > tools/libxl/libxl_internal.h | 5 +++++ > 2 files changed, 11 insertions(+), 1 deletions(-) > > diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c > index 638b9ab..5e1a207 100644 > --- a/tools/libxl/libxl_event.c > +++ b/tools/libxl/libxl_event.c > @@ -335,6 +335,9 @@ static void watchfd_callback(libxl__egc *egc, libxl__ev_fd *ev, > { > EGC_GC; > > + if (revents & (POLLERR|POLLHUP)) > + LIBXL__EVENT_DISASTER(egc, "unexpected poll event on watch fd", 0, 0); > + > for (;;) { > char **event = xs_check_watch(CTX->xsh); > if (!event) { > @@ -739,7 +742,9 @@ static int afterpoll_check_fd(libxl__poller *poller, > /* again, stale slot entry */ > return 0; > > - int revents = fds[slot].revents & events; > + assert(!(fds[slot].revents & POLLNVAL)); > + > + int revents = fds[slot].revents & (events | POLLERR | POLLHUP); > /* we mask in case requested events have changed */ > > return revents; > diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h > index a4b933b..af631fb 100644 > --- a/tools/libxl/libxl_internal.h > +++ b/tools/libxl/libxl_internal.h > @@ -127,6 +127,11 @@ void libxl__alloc_failed(libxl_ctx *, const char *func, > typedef struct libxl__ev_fd libxl__ev_fd; > typedef void libxl__ev_fd_callback(libxl__egc *egc, libxl__ev_fd *ev, > int fd, short events, short revents); > + /* Note that revents may contain POLLERR or POLLHUP regardless of > + * events; otherwise revents contains only bits in events. Contrary > + * to the documentation for poll(2), POLLERR and POLLHUP can occur > + * even if only POLLIN was set in events. (POLLNVAL is a fatal > + * error and will cause libxl event machinery to fail an assertion.) */ > struct libxl__ev_fd { > /* caller should include this in their own struct */ > /* read-only for caller, who may read only when registered: */