[PATCH v2 2/2] pager: make wait_for_pager a no-op for "cat"
- From
Rubén Justo <rjusto@gmail.com>
- Date
- Jul 23, 2024, 00:42 UTC
- Message-ID
- <a2d6169f-61ee-4a3f-9f8a-f791229c25a2@gmail.com>
- In-Reply-To
- <7c9ec43d-f52f-49b7-b1f3-fe3c85554006@gmail.com>
If we find that the configured pager is an empty string [*1*] or simply "cat" [*2*], then we return from `setup_pager()` silently without doing anything, allowing the output to go directly to the normal stdout.
If `setup_pager()` avoids forking a pager, then when the client calls the corresponding `wait_for_pager()`, we might fail trying to terminate a process that wasn't started.
One solution to avoid this problem could be to make the caller aware that `setup_pager()` did nothing, so it could avoid calling `wait_for_pager()`.
However, let's avoid shifting that responsibility to the caller and instead treat the call to `wait_for_pager()` as a no-op when we know we haven't forked a pager.
1.- 402461aab1 (pager: do not fork a pager if PAGER is set to empty.,
2006-04-16)2.- caef71a535 (Do not fork PAGER=cat, 2006-04-16)
Signed-off-by: Rubén Justo <rjusto@gmail.com> --- pager.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/pager.c b/pager.c index bea4345f6f..896f40fcd2 100644 --- a/pager.c +++ b/pager.c @@ -46,6 +46,9 @@ static void wait_for_pager_atexit(void) void wait_for_pager(void) { + if (old_fd1 == -1) + return; + finish_pager(); sigchain_pop_common(); unsetenv("GIT_PAGER_IN_USE");
-- 2.45.1