If the pager closes before the git command feeding the pager finishes, git is killed by a SIGPIPE and the corresponding exit code is 141. Since the pipe is just an implementation detail, it does not make sense for this error code to be user-facing. Handle SIGPIPEs by simply calling exit(0) in wait_for_pager_signal(). Introduce `test-tool pager` which infinitely prints `y` to the pager in order to test the new behavior. This cannot be tested with any existing git command because there are no other commands which produce infinite output. Without the change to pager.c, the newly introduced test fails. Reported-by: Vincent Lefevre <vincent@xxxxxxxxxx> Signed-off-by: Denton Liu <liu.denton@xxxxxxxxx> --- Sorry for the resend, it seems like vger has dropped the first patch. Makefile | 1 + pager.c | 2 ++ t/helper/test-pager.c | 12 ++++++++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t7006-pager.sh | 4 ++++ 6 files changed, 21 insertions(+) create mode 100644 t/helper/test-pager.c diff --git a/Makefile b/Makefile index 4edfda3e00..38a1a20f31 100644 --- a/Makefile +++ b/Makefile @@ -719,6 +719,7 @@ TEST_BUILTINS_OBJS += test-mktemp.o TEST_BUILTINS_OBJS += test-oid-array.o TEST_BUILTINS_OBJS += test-oidmap.o TEST_BUILTINS_OBJS += test-online-cpus.o +TEST_BUILTINS_OBJS += test-pager.o TEST_BUILTINS_OBJS += test-parse-options.o TEST_BUILTINS_OBJS += test-parse-pathspec-file.o TEST_BUILTINS_OBJS += test-path-utils.o diff --git a/pager.c b/pager.c index ee435de675..5922d99dc8 100644 --- a/pager.c +++ b/pager.c @@ -34,6 +34,8 @@ static void wait_for_pager_atexit(void) static void wait_for_pager_signal(int signo) { wait_for_pager(1); + if (signo == SIGPIPE) + exit(0); sigchain_pop(signo); raise(signo); } diff --git a/t/helper/test-pager.c b/t/helper/test-pager.c new file mode 100644 index 0000000000..feb68b8643 --- /dev/null +++ b/t/helper/test-pager.c @@ -0,0 +1,12 @@ +#include "test-tool.h" +#include "cache.h" + +int cmd__pager(int argc, const char **argv) +{ + if (argc > 1) + usage("\ttest-tool pager"); + + setup_pager(); + for (;;) + puts("y"); +} diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index 9d6d14d929..88269a7156 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -43,6 +43,7 @@ static struct test_cmd cmds[] = { { "oid-array", cmd__oid_array }, { "oidmap", cmd__oidmap }, { "online-cpus", cmd__online_cpus }, + { "pager", cmd__pager }, { "parse-options", cmd__parse_options }, { "parse-pathspec-file", cmd__parse_pathspec_file }, { "path-utils", cmd__path_utils }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index a6470ff62c..78900f7938 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -32,6 +32,7 @@ int cmd__mergesort(int argc, const char **argv); int cmd__mktemp(int argc, const char **argv); int cmd__oidmap(int argc, const char **argv); int cmd__online_cpus(int argc, const char **argv); +int cmd__pager(int argc, const char **argv); int cmd__parse_options(int argc, const char **argv); int cmd__parse_pathspec_file(int argc, const char** argv); int cmd__path_utils(int argc, const char **argv); diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index fdb450e446..2eb89e8f75 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -656,4 +656,8 @@ test_expect_success TTY 'git tag with auto-columns ' ' test_cmp expect actual ' +test_expect_success TTY 'SIGPIPE from pager returns success' ' + test_terminal env PAGER=true test-tool pager +' + test_done -- 2.30.0.478.g8a0d178c01