From: "Rubén Justo" <rjusto@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
Phillip Wood <phillip.wood@dunelm.org.uk>
Subject: [PATCH 2/4] pager: do not close fd 2 unnecessarily
Date: Thu, 25 Jul 2024 15:44:27 +0200 [thread overview]
Message-ID: <3fcb30a2-8a97-4b34-aa3d-b19ee54dc97e@gmail.com> (raw)
In-Reply-To: <76936fb1-446d-455f-b4e7-6e24dda3c17d@gmail.com>
We send errors to the pager since 61b80509e3 (sending errors to stdout
under $PAGER, 2008-02-16).
In a8335024c2 (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>
---
| 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
--git a/pager.c b/pager.c
index be6f4ee59f..251adfc2ad 100644
--- a/pager.c
+++ b/pager.c
@@ -14,6 +14,7 @@ int pager_use_color = 1;
static struct child_process pager_process;
static char *pager_program;
+static int close_fd2;
/* Is the value coming back from term_columns() just a guess? */
static int term_columns_guessed;
@@ -23,7 +24,8 @@ static void close_pager_fds(void)
{
/* signal EOF to pager */
close(1);
- close(2);
+ if (close_fd2)
+ close(2);
}
static void wait_for_pager_atexit(void)
@@ -141,8 +143,10 @@ void setup_pager(void)
/* original process continues, but writes to the pipe */
dup2(pager_process.in, 1);
- if (isatty(2))
+ if (isatty(2)) {
+ close_fd2 = 1;
dup2(pager_process.in, 2);
+ }
close(pager_process.in);
/* this makes sure that the parent terminates after the pager */
--
2.46.0.rc0.4.g6f4990c0d4
next prev parent reply other threads:[~2024-07-25 13:44 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-23 0:39 [PATCH v2 0/2] add-p P fixups Rubén Justo
2024-07-23 0:42 ` [PATCH v2 1/2] t3701: avoid one-shot export for shell functions Rubén Justo
2024-07-23 0:42 ` [PATCH v2 2/2] pager: make wait_for_pager a no-op for "cat" Rubén Justo
2024-07-23 0:54 ` [PATCH v2 0/2] add-p P fixups Junio C Hamano
2024-07-23 9:15 ` Phillip Wood
2024-07-23 16:52 ` Junio C Hamano
2024-07-23 22:08 ` Rubén Justo
2024-07-24 15:21 ` phillip.wood123
2024-07-24 16:12 ` Rubén Justo
2024-07-25 9:45 ` Phillip Wood
2024-07-25 12:16 ` Rubén Justo
2024-07-25 13:42 ` [PATCH 0/4] squash fixups in rj/add-p-pager Rubén Justo
2024-07-25 13:44 ` [PATCH 1/4] add-patch: test for 'p' command Rubén Justo
2024-07-25 13:44 ` Rubén Justo [this message]
2024-07-25 13:44 ` [PATCH 3/4] pager: introduce wait_for_pager Rubén Justo
2024-07-25 13:44 ` [PATCH 4/4] add-patch: render hunks through the pager Rubén Justo
2024-07-25 15:24 ` [PATCH v2 0/2] add-p P fixups Junio C Hamano
2024-07-25 16:41 ` Re* " Rubén Justo
2024-07-25 16:43 ` [PATCH 1/2] pager: introduce wait_for_pager Rubén Justo
2024-07-25 16:43 ` [PATCH 2/2] add-patch: render hunks through the pager Rubén Justo
2024-07-26 18:36 ` Junio C Hamano
2024-07-27 1:40 ` Junio C Hamano
2024-07-27 14:33 ` Rubén Justo
2024-07-26 18:24 ` Re* [PATCH v2 0/2] add-p P fixups Junio C Hamano
2024-07-26 19:22 ` Rubén Justo
2024-07-26 19:48 ` Junio C Hamano
2024-07-26 20:16 ` Rubén Justo
2024-07-28 9:11 ` Rubén Justo
2024-07-29 18:45 ` Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2024-07-12 0:57 [PATCH 0/4] use the pager in 'add -p' Rubén Justo
2024-07-12 1:00 ` [PATCH 2/4] pager: do not close fd 2 unnecessarily Rubén Justo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3fcb30a2-8a97-4b34-aa3d-b19ee54dc97e@gmail.com \
--to=rjusto@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=phillip.wood@dunelm.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).