Use the new libxl__pipe_nonblock and _close functions, rather than
open coding the same logic. Now the pipe is nonblocking, which avoids
a race which could result in libxl deadlocking in a multithreaded
program.
Reported-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Jim Fehlig <jfehlig@suse.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
* them; we wish the application good luck with understanding
* this if and when it reaps them. */
libxl__sigchld_notneeded(gc);
-
- if (ctx->sigchld_selfpipe[0] >= 0) {
- close(ctx->sigchld_selfpipe[0]);
- close(ctx->sigchld_selfpipe[1]);
- }
+ libxl__pipe_close(ctx->sigchld_selfpipe);
pthread_mutex_destroy(&ctx->lock);
int libxl__sigchld_needed(libxl__gc *gc) /* non-reentrant, idempotent */
{
- int r, rc;
+ int rc;
if (CTX->sigchld_selfpipe[0] < 0) {
- r = pipe(CTX->sigchld_selfpipe);
- if (r) {
- CTX->sigchld_selfpipe[0] = -1;
- LIBXL__LOG_ERRNO(CTX, LIBXL__LOG_ERROR,
- "failed to create sigchld pipe");
- rc = ERROR_FAIL;
- goto out;
- }
+ rc = libxl__pipe_nonblock(CTX, CTX->sigchld_selfpipe);
+ if (rc) goto out;
}
if (!libxl__ev_fd_isregistered(&CTX->sigchld_selfpipe_efd)) {
rc = libxl__ev_fd_register(gc, &CTX->sigchld_selfpipe_efd,