+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);
+}
+