X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=blobdiff_plain;f=cprogs%2Fcgi-fcgi-interp.c;h=f59640f4305eb86342d135462f7aa02e3a44e2c5;hp=35ce536a57e90e49fa836c0698b6a8c45624f925;hb=fa842b6dae3eeda6067a3cb5c774d311e4f1b3fc;hpb=ca7abd890b42e423354d323384adc9a08b718461 diff --git a/cprogs/cgi-fcgi-interp.c b/cprogs/cgi-fcgi-interp.c index 35ce536..f59640f 100644 --- a/cprogs/cgi-fcgi-interp.c +++ b/cprogs/cgi-fcgi-interp.c @@ -140,6 +140,7 @@ #include #include #include +#include #include @@ -581,6 +582,31 @@ static void alarm_handler(int dummy) { queue_alarm(); } +static void child_handler(int dummy) { + for (;;) { + int status; + pid_t got = waitpid(-1, &status, WNOHANG); + if (got == (pid_t)-1) err(127,"(stage2) waitpid"); + if (got != script_child) { + warn("(stage2) waitpid got status %d for unknown child [%lu]", + status, (unsigned long)got); + continue; + } + if (WIFEXITED(status)) { + int v = WEXITSTATUS(status); + if (v) warn("program failed with error exit status %d", v); + exit(status); + } else if (WIFSIGNALED(status)) { + int s = WTERMSIG(status); + err(status & 0xff, "program died due to fatal signal %s%s", + strsignal(s), WCOREDUMP(status) ? " (core dumped" : ""); + } else { + err(127, "program failed with crazy wait status %#x", status); + } + } + exit(127); +} + static void setup_handlers(void) { struct sigaction sa; int r;