git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/4] pager: save the original stderr when redirecting to pager

From
Jeff King <peff@peff.net>
Date
Mar 24, 2011, 17:46 UTC
Message-ID
<20110324174656.GA30685@sigill.intra.peff.net>
In-Reply-To
<20110324174556.GA30661@sigill.intra.peff.net>

When we redirect stdout to the pager, we also redirect stderr (if it would otherwise go to the terminal) so that error messages do not get overwritten by the pager.

However, some stderr output may still want to go to the terminal, because they are time-sensitive (like progress reports) and should be overwritten by the pager.

This patch stashes away the original stderr descriptor and creates a new stdio buffer for it.

Signed-off-by: Jeff King <peff@peff.net>
---
Same as the last iteration.
 cache.h |    2 ++
 pager.c |    7 ++++++-
 2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/cache.h b/cache.h
index f765cf5..73da139 100644
--- a/cache.h
+++ b/cache.h
@@ -1068,6 +1068,8 @@ extern int pager_use_color;
 extern const char *editor_program;
 extern const char *askpass_program;
 extern const char *excludes_file;
+extern FILE *original_stderr;
+extern int original_stderr_fd;
 
 /* base85 */
 int decode_85(char *dst, const char *line, int linelen);
diff --git a/pager.c b/pager.c
index dac358f..701926f 100644
--- a/pager.c
+++ b/pager.c
@@ -12,6 +12,8 @@
  */
 
 static int spawned_pager;
+FILE *original_stderr;
+int original_stderr_fd = -1;
 
 #ifndef WIN32
 static void pager_preexec(void)
@@ -97,8 +99,11 @@ void setup_pager(void)
 
 	/* original process continues, but writes to the pipe */
 	dup2(pager_process.in, 1);
-	if (isatty(2))
+	if (isatty(2)) {
+		original_stderr_fd = dup(2);
+		original_stderr = fdopen(original_stderr_fd, "w");
 		dup2(pager_process.in, 2);
+	}
 	close(pager_process.in);
 
 	/* this makes sure that the parent terminates after the pager */
-- 
1.7.4.41.g423da
Previous: Jeff KingNext: Jeff King
Message 16 of 24 in “builtin/diff.c: remove duplicated call to diff_result_code()”
  1. builtin/diff.c: remove duplicated call to diff_result_code()Junio C Hamano, Mar 22, 2011
  2. 1/3 diffcore-rename: refactor "too many candidates" logicJunio C Hamano, Mar 22, 2011
  3. 2/3 diffcore-rename: record filepair for rename srcJunio C Hamano, Mar 22, 2011
  4. 3/3 diffcore-rename: fall back to -C when -C -C busts the rename limitJunio C Hamano, Mar 22, 2011
  5. Jeff KingMar 23, 2011
  6. Junio C HamanoMar 23, 2011
  7. Jeff KingMar 23, 2011
  8. Jeff KingMar 23, 2011
  9. 1/3 pager: save the original stderr when redirecting to pagerJeff King, Mar 23, 2011
  10. 2/3 progress: use pager's original_stderr if availableJeff King, Mar 23, 2011
  11. 3/3 show: turn on rename progressJeff King, Mar 23, 2011
  12. Junio C HamanoMar 23, 2011
  13. Jeff KingMar 24, 2011
  14. Junio C HamanoMar 24, 2011
  15. Jeff KingMar 24, 2011
  16. 1/4 pager: save the original stderr when redirecting to pagerJeff King, Mar 24, 2011
  17. 2/4 progress: use pager's original_stderr if availableJeff King, Mar 24, 2011
  18. 3/4 show: turn on rename detection progress reportingJeff King, Mar 24, 2011
  19. Junio C HamanoMar 24, 2011
  20. Jeff KingMar 25, 2011
  21. 4/4 diff: turn on rename detection progress reportingJeff King, Mar 24, 2011
  22. Johannes SixtMar 25, 2011
  23. Jeff KingMar 25, 2011
  24. Junio C HamanoMar 24, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.