]> xenbits.xensource.com Git - xen.git/commitdiff
libxl: event system: pass gc, not just ctx, to internal sigchld manipulators
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 5 Nov 2013 16:17:42 +0000 (16:17 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 21 Nov 2013 18:47:24 +0000 (18:47 +0000)
We are going to want the gc for libxl__ev_fd_register.

No functional change in this patch.  Simply change the argument types,
and the actual arguments from ctx to gc.  Inside these functions, use
CTX (the macro which uses gc) rather than the old formal parameter
ctx.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
tools/libxl/libxl.c
tools/libxl/libxl_fork.c
tools/libxl/libxl_internal.h

index ed3293127d8600e20a56ae9d28a170a0d31a7743..b72e3a79d6555313a770b356fd6462ee3bf44cf9 100644 (file)
@@ -164,7 +164,7 @@ int libxl_ctx_free(libxl_ctx *ctx)
     /* If we have outstanding children, then the application inherits
      * them; we wish the application good luck with understanding
      * this if and when it reaps them. */
-    libxl__sigchld_removehandler(ctx);
+    libxl__sigchld_removehandler(gc);
 
     if (ctx->sigchld_selfpipe[0] >= 0) {
         close(ctx->sigchld_selfpipe[0]);
index b6f0b2d034d3005032ccbe8b39e50eb7076ac5a1..ae6184c33df5356e0af024952da03c0507073025 100644 (file)
@@ -175,23 +175,23 @@ static void sigchld_removehandler_core(void)
     sigchld_owner = 0;
 }
 
-void libxl__sigchld_removehandler(libxl_ctx *ctx) /* non-reentrant */
+void libxl__sigchld_removehandler(libxl__gc *gc) /* non-reentrant */
 {
     atfork_lock();
-    if (sigchld_owner == ctx)
+    if (sigchld_owner == CTX)
         sigchld_removehandler_core();
     atfork_unlock();
 }
 
-int libxl__sigchld_installhandler(libxl_ctx *ctx) /* non-reentrant */
+int libxl__sigchld_installhandler(libxl__gc *gc) /* non-reentrant */
 {
     int r, rc;
 
-    if (ctx->sigchld_selfpipe[0] < 0) {
-        r = pipe(ctx->sigchld_selfpipe);
+    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,
+            CTX->sigchld_selfpipe[0] = -1;
+            LIBXL__LOG_ERRNO(CTX, LIBXL__LOG_ERROR,
                              "failed to create sigchld pipe");
             rc = ERROR_FAIL;
             goto out;
@@ -199,11 +199,11 @@ int libxl__sigchld_installhandler(libxl_ctx *ctx) /* non-reentrant */
     }
 
     atfork_lock();
-    if (sigchld_owner != ctx) {
+    if (sigchld_owner != CTX) {
         struct sigaction ours;
 
         assert(!sigchld_owner);
-        sigchld_owner = ctx;
+        sigchld_owner = CTX;
 
         memset(&ours,0,sizeof(ours));
         ours.sa_handler = sigchld_handler;
@@ -241,11 +241,11 @@ int libxl__fork_selfpipe_active(libxl_ctx *ctx)
     return ctx->sigchld_selfpipe[0];
 }
 
-static void perhaps_removehandler(libxl_ctx *ctx)
+static void perhaps_removehandler(libxl__gc *gc)
 {
-    if (LIBXL_LIST_EMPTY(&ctx->children) &&
-        ctx->childproc_hooks->chldowner != libxl_sigchld_owner_libxl_always)
-        libxl__sigchld_removehandler(ctx);
+    if (LIBXL_LIST_EMPTY(&CTX->children) &&
+        CTX->childproc_hooks->chldowner != libxl_sigchld_owner_libxl_always)
+        libxl__sigchld_removehandler(gc);
 }
 
 static int childproc_reaped(libxl__egc *egc, pid_t pid, int status)
@@ -265,7 +265,7 @@ static int childproc_reaped(libxl__egc *egc, pid_t pid, int status)
     ch->pid = -1;
     ch->callback(egc, ch, pid, status);
 
-    perhaps_removehandler(CTX);
+    perhaps_removehandler(gc);
 
     return 0;
 }
@@ -333,7 +333,7 @@ pid_t libxl__ev_child_fork(libxl__gc *gc, libxl__ev_child *ch,
     int rc;
 
     if (chldmode_ours(CTX)) {
-        rc = libxl__sigchld_installhandler(CTX);
+        rc = libxl__sigchld_installhandler(gc);
         if (rc) goto out;
     }
 
@@ -363,7 +363,7 @@ pid_t libxl__ev_child_fork(libxl__gc *gc, libxl__ev_child *ch,
     rc = pid;
 
  out:
-    perhaps_removehandler(CTX);
+    perhaps_removehandler(gc);
     CTX_UNLOCK;
     return rc;
 }
@@ -385,10 +385,10 @@ void libxl_childproc_setmode(libxl_ctx *ctx, const libxl_childproc_hooks *hooks,
     switch (ctx->childproc_hooks->chldowner) {
     case libxl_sigchld_owner_mainloop:
     case libxl_sigchld_owner_libxl:
-        libxl__sigchld_removehandler(ctx);
+        libxl__sigchld_removehandler(gc);
         break;
     case libxl_sigchld_owner_libxl_always:
-        libxl__sigchld_installhandler(ctx);
+        libxl__sigchld_installhandler(gc);
         break;
     default:
         abort();
index 670234bfa6f752de03a9634fb2f2d5a7c5f73ff2..7310dc9377896927f38483735063274708ccfbbb 100644 (file)
@@ -837,8 +837,8 @@ _hidden void libxl__poller_wakeup(libxl__egc *egc, libxl__poller *p);
 
 /* Internal to fork and child reaping machinery */
 extern const libxl_childproc_hooks libxl__childproc_default_hooks;
-int libxl__sigchld_installhandler(libxl_ctx *ctx); /* non-reentrant;logs errs */
-void libxl__sigchld_removehandler(libxl_ctx *ctx); /* non-reentrant */
+int libxl__sigchld_installhandler(libxl__gc*); /* non-reentrant; logs errs */
+void libxl__sigchld_removehandler(libxl__gc*); /* non-reentrant */
 int libxl__fork_selfpipe_active(libxl_ctx *ctx); /* returns read fd or -1 */
 void libxl__fork_selfpipe_woken(libxl__egc *egc);
 int libxl__self_pipe_wakeup(int fd); /* returns 0 or -1 setting errno */