Merge branch 'jk/t7006-sigpipe-tests-fix'

The function to cull a child process and determine the exit status
had two separate code paths for normal callers and callers in a
signal handler, and the latter did not yield correct value when the
child has caught a signal.  The handling of the exit status has
been unified for these two code paths.  An existing test with
flakiness has also been corrected.

* jk/t7006-sigpipe-tests-fix:
  t7006: simplify exit-code checks for sigpipe tests
  t7006: clean up SIGPIPE handling in trace2 tests
  run-command: unify signal and regular logic for wait_or_whine()
This commit is contained in:
Junio C Hamano
2021-12-10 14:35:13 -08:00
2 changed files with 23 additions and 50 deletions

View File

@ -552,20 +552,17 @@ static int wait_or_whine(pid_t pid, const char *argv0, int in_signal)
while ((waiting = waitpid(pid, &status, 0)) < 0 && errno == EINTR)
; /* nothing */
if (in_signal) {
if (WIFEXITED(status))
code = WEXITSTATUS(status);
return code;
}
if (waiting < 0) {
failed_errno = errno;
error_errno("waitpid for %s failed", argv0);
if (!in_signal)
error_errno("waitpid for %s failed", argv0);
} else if (waiting != pid) {
error("waitpid is confused (%s)", argv0);
if (!in_signal)
error("waitpid is confused (%s)", argv0);
} else if (WIFSIGNALED(status)) {
code = WTERMSIG(status);
if (code != SIGINT && code != SIGQUIT && code != SIGPIPE)
if (!in_signal && code != SIGINT && code != SIGQUIT && code != SIGPIPE)
error("%s died of signal %d", argv0, code);
/*
* This return value is chosen so that code & 0xff
@ -576,10 +573,12 @@ static int wait_or_whine(pid_t pid, const char *argv0, int in_signal)
} else if (WIFEXITED(status)) {
code = WEXITSTATUS(status);
} else {
error("waitpid is confused (%s)", argv0);
if (!in_signal)
error("waitpid is confused (%s)", argv0);
}
clear_child_for_cleanup(pid);
if (!in_signal)
clear_child_for_cleanup(pid);
errno = failed_errno;
return code;