Skip to content

Commit 61ff12f

Browse files
avargitster
authored andcommitted
pager: refactor wait_for_pager() function
Refactor the wait_for_pager() function. Since 507d780 (pager: don't use unsafe functions in signal handlers, 2015-09-04) the wait_for_pager() and wait_for_pager_atexit() callers diverged on more than they shared. Let's extract the common code into a new close_pager_fds() helper, and move the parts unique to the only to callers to those functions. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e636282 commit 61ff12f

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

pager.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,25 @@
1111
static struct child_process pager_process = CHILD_PROCESS_INIT;
1212
static const char *pager_program;
1313

14-
static void wait_for_pager(int in_signal)
14+
static void close_pager_fds(void)
1515
{
16-
if (!in_signal) {
17-
fflush(stdout);
18-
fflush(stderr);
19-
}
2016
/* signal EOF to pager */
2117
close(1);
2218
close(2);
23-
if (in_signal)
24-
finish_command_in_signal(&pager_process);
25-
else
26-
finish_command(&pager_process);
2719
}
2820

2921
static void wait_for_pager_atexit(void)
3022
{
31-
wait_for_pager(0);
23+
fflush(stdout);
24+
fflush(stderr);
25+
close_pager_fds();
26+
finish_command(&pager_process);
3227
}
3328

3429
static void wait_for_pager_signal(int signo)
3530
{
36-
wait_for_pager(1);
31+
close_pager_fds();
32+
finish_command_in_signal(&pager_process);
3733
sigchain_pop(signo);
3834
raise(signo);
3935
}

0 commit comments

Comments
 (0)