1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-09 03:36:13 +02:00

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
commit 97991dfab7
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;

View File

@ -661,6 +661,13 @@ test_expect_success 'setup trace2' '
export GIT_TRACE2_BRIEF
'
test_expect_success 'setup large log output' '
perl -e "
print \"this is a long commit message\" x 50000
" >commit-msg &&
git commit --allow-empty -F commit-msg
'
test_expect_success TTY 'git returns SIGPIPE on early pager exit' '
test_when_finished "rm pager-used trace.normal" &&
test_config core.pager ">pager-used; head -n 1; exit 0" &&
@ -670,7 +677,7 @@ test_expect_success TTY 'git returns SIGPIPE on early pager exit' '
if test_have_prereq !MINGW
then
OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
{ test_terminal git log >/dev/null; OUT=$?; } &&
test_match_signal 13 "$OUT"
else
test_terminal git log
@ -691,7 +698,7 @@ test_expect_success TTY 'git returns SIGPIPE on early pager non-zero exit' '
if test_have_prereq !MINGW
then
OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
{ test_terminal git log >/dev/null; OUT=$?; } &&
test_match_signal 13 "$OUT"
else
test_terminal git log
@ -710,13 +717,7 @@ test_expect_success TTY 'git discards pager non-zero exit without SIGPIPE' '
export GIT_TRACE2 &&
test_when_finished "unset GIT_TRACE2" &&
if test_have_prereq !MINGW
then
OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
test "$OUT" -eq 0
else
test_terminal git log
fi &&
test_terminal git log &&
grep child_exit trace.normal >child-exits &&
test_line_count = 1 child-exits &&
@ -724,41 +725,14 @@ test_expect_success TTY 'git discards pager non-zero exit without SIGPIPE' '
test_path_is_file pager-used
'
test_expect_success TTY 'git discards nonexisting pager without SIGPIPE' '
test_when_finished "rm pager-used trace.normal" &&
test_config core.pager "wc >pager-used; does-not-exist" &&
GIT_TRACE2="$(pwd)/trace.normal" &&
export GIT_TRACE2 &&
test_when_finished "unset GIT_TRACE2" &&
if test_have_prereq !MINGW
then
OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
test "$OUT" -eq 0
else
test_terminal git log
fi &&
grep child_exit trace.normal >child-exits &&
test_line_count = 1 child-exits &&
grep " code:127 " child-exits &&
test_path_is_file pager-used
'
test_expect_success TTY 'git attempts to page to nonexisting pager command, gets SIGPIPE' '
test_expect_success TTY 'git skips paging nonexisting command' '
test_when_finished "rm trace.normal" &&
test_config core.pager "does-not-exist" &&
GIT_TRACE2="$(pwd)/trace.normal" &&
export GIT_TRACE2 &&
test_when_finished "unset GIT_TRACE2" &&
if test_have_prereq !MINGW
then
OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
test_match_signal 13 "$OUT"
else
test_terminal git log
fi &&
test_terminal git log &&
grep child_exit trace.normal >child-exits &&
test_line_count = 1 child-exits &&
@ -767,14 +741,14 @@ test_expect_success TTY 'git attempts to page to nonexisting pager command, gets
test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' '
test_when_finished "rm pager-used trace.normal" &&
test_config core.pager ">pager-used; test-tool sigchain" &&
test_config core.pager ">pager-used; exec test-tool sigchain" &&
GIT_TRACE2="$(pwd)/trace.normal" &&
export GIT_TRACE2 &&
test_when_finished "unset GIT_TRACE2" &&
if test_have_prereq !MINGW
then
OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
{ test_terminal git log >/dev/null; OUT=$?; } &&
test_match_signal 13 "$OUT"
else
test_terminal git log