]> xenbits.xensource.com Git - libvirt.git/commitdiff
Block SIGPIPE around virExec hook functions
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 21 Jan 2011 17:48:48 +0000 (17:48 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 9 Feb 2011 16:21:06 +0000 (16:21 +0000)
Some functionality run in virExec hooks may do I/O which
can trigger SIGPIPE. Renable SIGPIPE blocking around the
hook function

* src/util/util.c: Block SIGPIPE around hooks

src/util/util.c

index ee04ca9ff865c38584c8cd54343a3b5e17bc85dc..9ac76c6c2c7806e347060c5eb7e10e396a75e0e6 100644 (file)
@@ -644,12 +644,34 @@ __virExec(const char *const*argv,
         }
     }
 
-    if (hook)
+    if (hook) {
+        /* virFork reset all signal handlers to the defaults.
+         * This is good for the child process, but our hook
+         * risks running something that generates SIGPIPE,
+         * so we need to temporarily block that again
+         */
+        struct sigaction waxon, waxoff;
+        waxoff.sa_handler = SIG_IGN;
+        waxoff.sa_flags = 0;
+        memset(&waxon, 0, sizeof(waxon));
+        if (sigaction(SIGPIPE, &waxoff, &waxon) < 0) {
+            virReportSystemError(errno, "%s",
+                                 _("Could not disable SIGPIPE"));
+            goto fork_error;
+        }
+
         if ((hook)(data) != 0) {
             VIR_DEBUG0("Hook function failed.");
             goto fork_error;
         }
 
+        if (sigaction(SIGPIPE, &waxon, NULL) < 0) {
+            virReportSystemError(errno, "%s",
+                                 _("Could not re-enable SIGPIPE"));
+            goto fork_error;
+        }
+    }
+
     /* The steps above may need todo something privileged, so
      * we delay clearing capabilities until the last minute */
     if ((flags & VIR_EXEC_CLEAR_CAPS) &&