Skip to content

Commit 3f58806

Browse files
Ben Peartdscho
Ben Peart
authored andcommitted
pager: fix order of atexit() calls
This is just a bug fix to git so that the pager won't close stdin/out before other atexit functions run. The easy way to repro the bug is to turn on GIT_TRACE_PERFORMANCE and run a command that runs the pager. Then notice you don't get your performance data at the end. With this fix, you do actually get the performance trace data. Signed-off-by: Ben Peart <[email protected]>
1 parent 7c9fbc0 commit 3f58806

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,7 @@ extern void write_file(const char *path, const char *fmt, ...);
16621662

16631663
/* pager.c */
16641664
extern void setup_pager(void);
1665+
extern void wait_for_pager_atexit(void);
16651666
extern int pager_in_use(void);
16661667
extern int pager_use_color;
16671668
extern int term_columns(void);

git.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,12 @@ int cmd_main(int argc, const char **argv)
782782
cmd = slash + 1;
783783
}
784784

785+
/*
786+
* wait_for_pager_atexit will close stdout/stderr so it needs to be
787+
* registered first so that it will execute last and not close the
788+
* handles until all other atexit handlers have finished
789+
*/
790+
atexit(wait_for_pager_atexit);
785791
trace_command_performance(argv);
786792

787793
/*

pager.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ static void wait_for_pager(int in_signal)
2626
finish_command(&pager_process);
2727
}
2828

29-
static void wait_for_pager_atexit(void)
29+
30+
static int run_wait_for_pager_atexit = 0;
31+
void wait_for_pager_atexit(void)
3032
{
31-
wait_for_pager(0);
33+
if (run_wait_for_pager_atexit)
34+
wait_for_pager(0);
3235
}
3336

3437
static void wait_for_pager_signal(int signo)
@@ -137,7 +140,7 @@ void setup_pager(void)
137140

138141
/* this makes sure that the parent terminates after the pager */
139142
sigchain_push_common(wait_for_pager_signal);
140-
atexit(wait_for_pager_atexit);
143+
run_wait_for_pager_atexit = 1;
141144
}
142145

143146
int pager_in_use(void)

0 commit comments

Comments
 (0)