Skip to content

Commit be8fc53

Browse files
avargitster
authored andcommitted
pager: properly log pager exit code when signalled
When git invokes a pager that exits with non-zero the common case is that we'll already return the correct SIGPIPE failure from git itself, but the exit code logged in trace2 has always been incorrectly reported[1]. Fix that and log the correct exit code in the logs. Since this gives us something to test outside of our recently-added tests needing a !MINGW prerequisite, let's refactor the test to run on MINGW and actually check for SIGPIPE outside of MINGW. The wait_or_whine() is only called with a true "in_signal" from from finish_command_in_signal(), which in turn is only used in pager.c. The "in_signal && !WIFEXITED(status)" case is not covered by tests. Let's log the default -1 in that case for good measure. 1. The incorrect logging of the exit code in was seemingly copy/pasted into finish_command_in_signal() in ee4512e (trace2: create new combined trace facility, 2019-02-22) Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 85db79a commit be8fc53

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

run-command.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,9 @@ static int wait_or_whine(pid_t pid, const char *argv0, int in_signal)
552552
while ((waiting = waitpid(pid, &status, 0)) < 0 && errno == EINTR)
553553
; /* nothing */
554554
if (in_signal) {
555-
return 0;
555+
if (WIFEXITED(status))
556+
code = WEXITSTATUS(status);
557+
return code;
556558
}
557559

558560
if (waiting < 0) {

t/t7006-pager.sh

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,17 @@ test_expect_success TTY 'git tag with auto-columns ' '
656656
test_cmp expect actual
657657
'
658658

659+
test_expect_success 'setup trace2' '
660+
GIT_TRACE2_BRIEF=1 &&
661+
export GIT_TRACE2_BRIEF
662+
'
663+
659664
test_expect_success TTY 'git returns SIGPIPE on early pager exit' '
660-
test_when_finished "rm pager-used" &&
665+
test_when_finished "rm pager-used trace.normal" &&
661666
test_config core.pager ">pager-used; head -n 1; exit 0" &&
667+
GIT_TRACE2="$(pwd)/trace.normal" &&
668+
export GIT_TRACE2 &&
669+
test_when_finished "unset GIT_TRACE2" &&
662670
663671
if test_have_prereq !MINGW
664672
then
@@ -667,12 +675,19 @@ test_expect_success TTY 'git returns SIGPIPE on early pager exit' '
667675
else
668676
test_terminal git log
669677
fi &&
678+
679+
grep child_exit trace.normal >child-exits &&
680+
test_line_count = 1 child-exits &&
681+
grep " code:0 " child-exits &&
670682
test_path_is_file pager-used
671683
'
672684

673685
test_expect_success TTY 'git returns SIGPIPE on early pager non-zero exit' '
674-
test_when_finished "rm pager-used" &&
686+
test_when_finished "rm pager-used trace.normal" &&
675687
test_config core.pager ">pager-used; head -n 1; exit 1" &&
688+
GIT_TRACE2="$(pwd)/trace.normal" &&
689+
export GIT_TRACE2 &&
690+
test_when_finished "unset GIT_TRACE2" &&
676691
677692
if test_have_prereq !MINGW
678693
then
@@ -681,12 +696,19 @@ test_expect_success TTY 'git returns SIGPIPE on early pager non-zero exit' '
681696
else
682697
test_terminal git log
683698
fi &&
699+
700+
grep child_exit trace.normal >child-exits &&
701+
test_line_count = 1 child-exits &&
702+
grep " code:1 " child-exits &&
684703
test_path_is_file pager-used
685704
'
686705

687706
test_expect_success TTY 'git discards pager non-zero exit without SIGPIPE' '
688-
test_when_finished "rm pager-used" &&
707+
test_when_finished "rm pager-used trace.normal" &&
689708
test_config core.pager "wc >pager-used; exit 1" &&
709+
GIT_TRACE2="$(pwd)/trace.normal" &&
710+
export GIT_TRACE2 &&
711+
test_when_finished "unset GIT_TRACE2" &&
690712
691713
if test_have_prereq !MINGW
692714
then
@@ -695,12 +717,19 @@ test_expect_success TTY 'git discards pager non-zero exit without SIGPIPE' '
695717
else
696718
test_terminal git log
697719
fi &&
720+
721+
grep child_exit trace.normal >child-exits &&
722+
test_line_count = 1 child-exits &&
723+
grep " code:1 " child-exits &&
698724
test_path_is_file pager-used
699725
'
700726

701727
test_expect_success TTY 'git discards nonexisting pager without SIGPIPE' '
702-
test_when_finished "rm pager-used" &&
728+
test_when_finished "rm pager-used trace.normal" &&
703729
test_config core.pager "wc >pager-used; does-not-exist" &&
730+
GIT_TRACE2="$(pwd)/trace.normal" &&
731+
export GIT_TRACE2 &&
732+
test_when_finished "unset GIT_TRACE2" &&
704733
705734
if test_have_prereq !MINGW
706735
then
@@ -709,24 +738,39 @@ test_expect_success TTY 'git discards nonexisting pager without SIGPIPE' '
709738
else
710739
test_terminal git log
711740
fi &&
741+
742+
grep child_exit trace.normal >child-exits &&
743+
test_line_count = 1 child-exits &&
744+
grep " code:127 " child-exits &&
712745
test_path_is_file pager-used
713746
'
714747

715748
test_expect_success TTY 'git attempts to page to nonexisting pager command, gets SIGPIPE' '
749+
test_when_finished "rm trace.normal" &&
716750
test_config core.pager "does-not-exist" &&
751+
GIT_TRACE2="$(pwd)/trace.normal" &&
752+
export GIT_TRACE2 &&
753+
test_when_finished "unset GIT_TRACE2" &&
717754
718755
if test_have_prereq !MINGW
719756
then
720757
OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
721758
test_match_signal 13 "$OUT"
722759
else
723760
test_terminal git log
724-
fi
761+
fi &&
762+
763+
grep child_exit trace.normal >child-exits &&
764+
test_line_count = 1 child-exits &&
765+
grep " code:-1 " child-exits
725766
'
726767

727768
test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' '
728-
test_when_finished "rm pager-used" &&
769+
test_when_finished "rm pager-used trace.normal" &&
729770
test_config core.pager ">pager-used; test-tool sigchain" &&
771+
GIT_TRACE2="$(pwd)/trace.normal" &&
772+
export GIT_TRACE2 &&
773+
test_when_finished "unset GIT_TRACE2" &&
730774
731775
if test_have_prereq !MINGW
732776
then
@@ -735,6 +779,10 @@ test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' '
735779
else
736780
test_terminal git log
737781
fi &&
782+
783+
grep child_exit trace.normal >child-exits &&
784+
test_line_count = 1 child-exits &&
785+
grep " code:143 " child-exits &&
738786
test_path_is_file pager-used
739787
'
740788

0 commit comments

Comments
 (0)