Skip to content

Commit

Permalink
pager: fix order of atexit() calls
Browse files Browse the repository at this point in the history
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 <Ben.Peart@microsoft.com>
  • Loading branch information
Ben Peart authored and dscho committed Dec 15, 2018
1 parent 7c9fbc0 commit 3f58806
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,7 @@ extern void write_file(const char *path, const char *fmt, ...);

/* pager.c */
extern void setup_pager(void);
extern void wait_for_pager_atexit(void);
extern int pager_in_use(void);
extern int pager_use_color;
extern int term_columns(void);
Expand Down
6 changes: 6 additions & 0 deletions git.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,12 @@ int cmd_main(int argc, const char **argv)
cmd = slash + 1;
}

/*
* wait_for_pager_atexit will close stdout/stderr so it needs to be
* registered first so that it will execute last and not close the
* handles until all other atexit handlers have finished
*/
atexit(wait_for_pager_atexit);
trace_command_performance(argv);

/*
Expand Down
9 changes: 6 additions & 3 deletions pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ static void wait_for_pager(int in_signal)
finish_command(&pager_process);
}

static void wait_for_pager_atexit(void)

static int run_wait_for_pager_atexit = 0;
void wait_for_pager_atexit(void)
{
wait_for_pager(0);
if (run_wait_for_pager_atexit)
wait_for_pager(0);
}

static void wait_for_pager_signal(int signo)
Expand Down Expand Up @@ -137,7 +140,7 @@ void setup_pager(void)

/* this makes sure that the parent terminates after the pager */
sigchain_push_common(wait_for_pager_signal);
atexit(wait_for_pager_atexit);
run_wait_for_pager_atexit = 1;
}

int pager_in_use(void)
Expand Down

0 comments on commit 3f58806

Please sign in to comment.