pager: do not close fd 2 unnecessarily
We send errors to the pager since61b80509e3
(sending errors to stdout under $PAGER, 2008-02-16). Ina8335024c2
(pager: do not dup2 stderr if it is already redirected, 2008-12-15) an exception was introduced to avoid redirecting stderr if it is not connected to a terminal. In such exceptional cases, the close(STDERR_FILENO) we're doing in close_pager_fds, is unnecessary. Furthermore, in a subsequent commit we're going to introduce changes that will involve using close_pager_fds multiple times. With this in mind, controlling when we want to close stderr, become sensible. Let's close(STDERR_FILENO) only when necessary, and pave the way for the upcoming changes. Signed-off-by: Rubén Justo <rjusto@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
7309be1fc5
commit
da9ef60c8f
8
pager.c
8
pager.c
@ -14,6 +14,7 @@ int pager_use_color = 1;
|
|||||||
|
|
||||||
static struct child_process pager_process;
|
static struct child_process pager_process;
|
||||||
static char *pager_program;
|
static char *pager_program;
|
||||||
|
static int close_fd2;
|
||||||
|
|
||||||
/* Is the value coming back from term_columns() just a guess? */
|
/* Is the value coming back from term_columns() just a guess? */
|
||||||
static int term_columns_guessed;
|
static int term_columns_guessed;
|
||||||
@ -23,7 +24,8 @@ static void close_pager_fds(void)
|
|||||||
{
|
{
|
||||||
/* signal EOF to pager */
|
/* signal EOF to pager */
|
||||||
close(1);
|
close(1);
|
||||||
close(2);
|
if (close_fd2)
|
||||||
|
close(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wait_for_pager_atexit(void)
|
static void wait_for_pager_atexit(void)
|
||||||
@ -141,8 +143,10 @@ void setup_pager(void)
|
|||||||
|
|
||||||
/* original process continues, but writes to the pipe */
|
/* original process continues, but writes to the pipe */
|
||||||
dup2(pager_process.in, 1);
|
dup2(pager_process.in, 1);
|
||||||
if (isatty(2))
|
if (isatty(2)) {
|
||||||
|
close_fd2 = 1;
|
||||||
dup2(pager_process.in, 2);
|
dup2(pager_process.in, 2);
|
||||||
|
}
|
||||||
close(pager_process.in);
|
close(pager_process.in);
|
||||||
|
|
||||||
/* this makes sure that the parent terminates after the pager */
|
/* this makes sure that the parent terminates after the pager */
|
||||||
|
Reference in New Issue
Block a user