[project @ 2005-01-31 21:07:15 by panne]
[ghc-base.git] / cbits / runProcess.c
index 320f3bf..8358605 100644 (file)
@@ -6,7 +6,7 @@
 \r
 #include "HsBase.h"\r
 \r
-#if defined(mingw32_TARGET_OS)\r
+#if defined(mingw32_HOST_OS)\r
 #include <windows.h>\r
 #include <stdlib.h>\r
 #endif\r
 #include <signal.h>\r
 #endif\r
 \r
-#if !defined(mingw32_TARGET_OS) && !defined(__MINGW32__)\r
+#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)\r
 /* ----------------------------------------------------------------------------\r
    UNIX versions\r
    ------------------------------------------------------------------------- */\r
 \r
 ProcHandle\r
 runProcess (char *const args[], char *workingDirectory, char **environment, \r
-           int fdStdInput, int fdStdOutput, int fdStdError)\r
+           int fdStdInput, int fdStdOutput, int fdStdError,\r
+           int set_inthandler, long inthandler, \r
+           int set_quithandler, long quithandler)\r
 {\r
     int pid;\r
     struct sigaction dfl;\r
@@ -48,27 +50,18 @@ runProcess (char *const args[], char *workingDirectory, char **environment,
            chdir (workingDirectory);\r
        }\r
        \r
-       /*\r
-        * Restore SIGINT and SIGQUIT to default actions\r
-        *\r
-        * Glyn Clemments writes:\r
-        * For your purposes, runProcess + waitForProcess is probably\r
-        * the way to go. Except that runProcess appears to be missing\r
-        * the usual signal handling. system() ignores SIGINT and\r
-        * SIGQUIT in the parent, and resets them to their defaults in\r
-        * the child; it also blocks SIGCHLD in the parent. runProcess\r
-        * may need to do something similar; it should probably at\r
-        * least reset SIGINT and SIGQUIT in the child, in case they\r
-        * are ignored in the parent. The parent can set up its own\r
-        * signal handling, but the only place it can control the\r
-        * child's signal handling is between the fork() and the\r
-        * exec(), so if runProcess doesn't do it, it won't get done.\r
+       /* Set the SIGINT/SIGQUIT signal handlers in the child, if requested \r
         */\r
-        dfl.sa_handler = SIG_DFL;\r
         (void)sigemptyset(&dfl.sa_mask);\r
         dfl.sa_flags = 0;\r
-       (void)sigaction(SIGINT, &dfl, NULL);\r
-       (void)sigaction(SIGQUIT,  &dfl, NULL);\r
+       if (set_inthandler) {\r
+           dfl.sa_handler = (void *)inthandler;\r
+           (void)sigaction(SIGINT, &dfl, NULL);\r
+       }\r
+       if (set_quithandler) {\r
+           dfl.sa_handler = (void *)quithandler;\r
+           (void)sigaction(SIGQUIT,  &dfl, NULL);\r
+       }\r
 \r
        dup2 (fdStdInput,  STDIN_FILENO);\r
        dup2 (fdStdOutput, STDOUT_FILENO);\r