mirror of
https://github.com/git-for-windows/git.git
synced 2025-12-13 08:41:13 -06:00
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>
This commit is contained in:
parent
e6362826a0
commit
61ff12fa50
18
pager.c
18
pager.c
@ -11,29 +11,25 @@
|
|||||||
static struct child_process pager_process = CHILD_PROCESS_INIT;
|
static struct child_process pager_process = CHILD_PROCESS_INIT;
|
||||||
static const char *pager_program;
|
static const char *pager_program;
|
||||||
|
|
||||||
static void wait_for_pager(int in_signal)
|
static void close_pager_fds(void)
|
||||||
{
|
{
|
||||||
if (!in_signal) {
|
|
||||||
fflush(stdout);
|
|
||||||
fflush(stderr);
|
|
||||||
}
|
|
||||||
/* signal EOF to pager */
|
/* signal EOF to pager */
|
||||||
close(1);
|
close(1);
|
||||||
close(2);
|
close(2);
|
||||||
if (in_signal)
|
|
||||||
finish_command_in_signal(&pager_process);
|
|
||||||
else
|
|
||||||
finish_command(&pager_process);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wait_for_pager_atexit(void)
|
static void wait_for_pager_atexit(void)
|
||||||
{
|
{
|
||||||
wait_for_pager(0);
|
fflush(stdout);
|
||||||
|
fflush(stderr);
|
||||||
|
close_pager_fds();
|
||||||
|
finish_command(&pager_process);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wait_for_pager_signal(int signo)
|
static void wait_for_pager_signal(int signo)
|
||||||
{
|
{
|
||||||
wait_for_pager(1);
|
close_pager_fds();
|
||||||
|
finish_command_in_signal(&pager_process);
|
||||||
sigchain_pop(signo);
|
sigchain_pop(signo);
|
||||||
raise(signo);
|
raise(signo);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user