X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=cbits%2FrunProcess.c;h=82fa97e594f8f3e761a30ba82b8e0e79ac4b68de;hb=b1f2e321ceac8fcfc1f0756e2f5c2585fbd00b3c;hp=56d4eab90d05e5289285a820482c244c53285ee5;hpb=ec3ba94b254bd444e7a1c560c1d91c4879948c69;p=ghc-base.git diff --git a/cbits/runProcess.c b/cbits/runProcess.c index 56d4eab..82fa97e 100644 --- a/cbits/runProcess.c +++ b/cbits/runProcess.c @@ -30,7 +30,9 @@ ProcHandle runProcess (char *const args[], char *workingDirectory, char **environment, - int fdStdInput, int fdStdOutput, int fdStdError) + int fdStdInput, int fdStdOutput, int fdStdError, + int set_inthandler, long inthandler, + int set_quithandler, long quithandler) { int pid; struct sigaction dfl; @@ -48,27 +50,18 @@ runProcess (char *const args[], char *workingDirectory, char **environment, chdir (workingDirectory); } - /* - * Restore SIGINT and SIGQUIT to default actions - * - * Glyn Clemments writes: - * For your purposes, runProcess + waitForProcess is probably - * the way to go. Except that runProcess appears to be missing - * the usual signal handling. system() ignores SIGINT and - * SIGQUIT in the parent, and resets them to their defaults in - * the child; it also blocks SIGCHLD in the parent. runProcess - * may need to do something similar; it should probably at - * least reset SIGINT and SIGQUIT in the child, in case they - * are ignored in the parent. The parent can set up its own - * signal handling, but the only place it can control the - * child's signal handling is between the fork() and the - * exec(), so if runProcess doesn't do it, it won't get done. + /* Set the SIGINT/SIGQUIT signal handlers in the child, if requested */ - dfl.sa_handler = SIG_DFL; (void)sigemptyset(&dfl.sa_mask); dfl.sa_flags = 0; - (void)sigaction(SIGINT, &dfl, NULL); - (void)sigaction(SIGQUIT, &dfl, NULL); + if (set_inthandler) { + dfl.sa_handler = (void *)inthandler; + (void)sigaction(SIGINT, &dfl, NULL); + } + if (set_quithandler) { + dfl.sa_handler = (void *)quithandler; + (void)sigaction(SIGQUIT, &dfl, NULL); + } dup2 (fdStdInput, STDIN_FILENO); dup2 (fdStdOutput, STDOUT_FILENO); @@ -160,11 +153,11 @@ terminateProcess (ProcHandle handle) int getProcessExitCode (ProcHandle handle, int *pExitCode) { - int wstat; + int wstat, res; *pExitCode = 0; - if (waitpid(handle, &wstat, WNOHANG) > 0) + if ((res = waitpid(handle, &wstat, WNOHANG)) > 0) { if (WIFEXITED(wstat)) { @@ -183,7 +176,15 @@ getProcessExitCode (ProcHandle handle, int *pExitCode) } } - return 0; + if (res == 0) return 0; + + if (errno == ECHILD) + { + *pExitCode = 0; + return 1; + } + + return -1; } int waitForProcess (ProcHandle handle)