| 556 | } |
| 557 | |
| 558 | static int wait_or_whine(pid_t pid, const char *argv0, int in_signal) |
| 559 | { |
| 560 | int status, code = -1; |
| 561 | pid_t waiting; |
| 562 | int failed_errno = 0; |
| 563 | |
| 564 | while ((waiting = waitpid(pid, &status, 0)) < 0 && errno == EINTR) |
| 565 | ; /* nothing */ |
| 566 | |
| 567 | if (waiting < 0) { |
| 568 | failed_errno = errno; |
| 569 | if (!in_signal) |
| 570 | error_errno("waitpid for %s failed", argv0); |
| 571 | } else if (waiting != pid) { |
| 572 | if (!in_signal) |
| 573 | error("waitpid is confused (%s)", argv0); |
| 574 | } else if (WIFSIGNALED(status)) { |
| 575 | code = WTERMSIG(status); |
| 576 | if (!in_signal && code != SIGINT && code != SIGQUIT && code != SIGPIPE) |
| 577 | error("%s died of signal %d", argv0, code); |
| 578 | /* |
| 579 | * This return value is chosen so that code & 0xff |
| 580 | * mimics the exit code that a POSIX shell would report for |
| 581 | * a program that died from this signal. |
| 582 | */ |
| 583 | code += 128; |
| 584 | } else if (WIFEXITED(status)) { |
| 585 | code = WEXITSTATUS(status); |
| 586 | } else { |
| 587 | if (!in_signal) |
| 588 | error("waitpid is confused (%s)", argv0); |
| 589 | } |
| 590 | |
| 591 | if (!in_signal) |
| 592 | clear_child_for_cleanup(pid); |
| 593 | |
| 594 | errno = failed_errno; |
| 595 | return code; |
| 596 | } |
| 597 | |
| 598 | static void trace_add_env(struct strbuf *dst, const char *const *deltaenv) |
| 599 | { |
no test coverage detected