pager: refactor wait_for_pager() function

Refactor the wait_for_pager() function. Since 507d7804c0b (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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 2, 2021 at 02:59 UTC 61ff12fa50b051141dd3b451d74dde76a87fece3
1 file changed +7 -11
pager.c
+7 -11
@@ -11,29 +11,25 @@
11 static struct child_process pager_process = CHILD_PROCESS_INIT;
12 static const char *pager_program;
13
14 -static void wait_for_pager(int in_signal)
14 +static void close_pager_fds(void)
15 {
16 - if (!in_signal) {
17 - fflush(stdout);
18 - fflush(stderr);
19 - }
16 /* signal EOF to pager */
17 close(1);
18 close(2);
23 - if (in_signal)
24 - finish_command_in_signal(&pager_process);
25 - else
26 - finish_command(&pager_process);
19 }
20
21 static void wait_for_pager_atexit(void)
22 {
31 - wait_for_pager(0);
23 + fflush(stdout);
24 + fflush(stderr);
25 + close_pager_fds();
26 + finish_command(&pager_process);
27 }
28
29 static void wait_for_pager_signal(int signo)
30 {
36 - wait_for_pager(1);
31 + close_pager_fds();
32 + finish_command_in_signal(&pager_process);
33 sigchain_pop(signo);
34 raise(signo);
35 }