From: Ian Jackson Date: Thu, 16 Jan 2014 16:37:44 +0000 (+0000) Subject: libxl: fork: Break out checked_waitpid X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~5617 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=8398e64dff171eb6e63238f4c9b4478403a88201;p=xen.git libxl: fork: Break out checked_waitpid This is a simple error-handling wrapper for waitpid. We're going to want to call waitpid somewhere else and this avoids some of the duplication. No functional change in this patch. (Technically, we used to check chldmode_ours again in the EINTR case, and don't now, but that can't have changed because we continuously hold the libxl ctx lock.) Signed-off-by: Ian Jackson Cc: Jim Fehlig Cc: Ian Campbell Acked-by: Ian Campbell --- diff --git a/tools/libxl/libxl_fork.c b/tools/libxl/libxl_fork.c index 4ae9f94836..2252370a11 100644 --- a/tools/libxl/libxl_fork.c +++ b/tools/libxl/libxl_fork.c @@ -155,6 +155,22 @@ int libxl__carefd_fd(const libxl__carefd *cf) * Actual child process handling */ +/* Like waitpid(,,WNOHANG) but handles all errors except ECHILD. */ +static pid_t checked_waitpid(libxl__egc *egc, pid_t want, int *status) +{ + for (;;) { + pid_t got = waitpid(want, status, WNOHANG); + if (got != -1) + return got; + if (errno == ECHILD) + return got; + if (errno == EINTR) + continue; + LIBXL__EVENT_DISASTER(egc, "waitpid() failed", errno, 0); + return 0; + } +} + static void sigchld_selfpipe_handler(libxl__egc *egc, libxl__ev_fd *ev, int fd, short events, short revents); @@ -331,16 +347,10 @@ static void sigchld_selfpipe_handler(libxl__egc *egc, libxl__ev_fd *ev, while (chldmode_ours(CTX, 0) /* in case the app changes the mode */) { int status; - pid_t pid = waitpid(-1, &status, WNOHANG); - - if (pid == 0) return; + pid_t pid = checked_waitpid(egc, -1, &status); - if (pid == -1) { - if (errno == ECHILD) return; - if (errno == EINTR) continue; - LIBXL__EVENT_DISASTER(egc, "waitpid() failed", errno, 0); + if (pid == 0 || pid == -1 /* ECHILD */) return; - } int rc = childproc_reaped(egc, pid, status);