Skip to content

Commit a3da882

Browse files
peffgitster
authored andcommitted
pager: do wait_for_pager on signal death
Since ea27a18 (spawn pager via run_command interface), the original git process actually does git work, and the pager is a child process (actually, on Windows it has always been that way, since Windows lacks fork). After spawning the pager, we register an atexit() handler that waits for the pager to finish. Unfortunately, that handler does not always run. In particular, if git is killed by a signal, then we exit immediately. The calling shell then thinks that git is done; however, the pager is still trying to run and impact the terminal. The result can be seen by running a long git process with a pager (e.g., "git log -p") and hitting ^C. Depending on your config, you should see the shell prompt, but pressing a key causes the pager to do any terminal de-initialization sequence. This patch just intercepts any death-dealing signals and waits for the pager before dying. Under typical less configuration, that means hitting ^C will cause git to stop generating output, but the pager will keep running. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 57b235a commit a3da882

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pager.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "cache.h"
22
#include "run-command.h"
3+
#include "sigchain.h"
34

45
/*
56
* This is split up from the rest of git so that we can do
@@ -38,6 +39,13 @@ static void wait_for_pager(void)
3839
finish_command(&pager_process);
3940
}
4041

42+
static void wait_for_pager_signal(int signo)
43+
{
44+
wait_for_pager();
45+
sigchain_pop(signo);
46+
raise(signo);
47+
}
48+
4149
void setup_pager(void)
4250
{
4351
const char *pager = getenv("GIT_PAGER");
@@ -75,6 +83,7 @@ void setup_pager(void)
7583
close(pager_process.in);
7684

7785
/* this makes sure that the parent terminates after the pager */
86+
sigchain_push_common(wait_for_pager_signal);
7887
atexit(wait_for_pager);
7988
}
8089

0 commit comments

Comments
 (0)