chiark / gitweb /
pager: also redirect stderr
authorLennart Poettering <lennart@poettering.net>
Thu, 27 Aug 2015 22:13:34 +0000 (00:13 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 09:19:06 +0000 (10:19 +0100)
It's really confusing if stdout goes to the pager, but stderr is written
directly to the screen. Hence, make sure both stdout and stderr are
passed to the pager when doing autopaging.

src/shared/pager.c

index d6474030c444d312d366f8faef04c7100bfa44de..1c1cf1605a1db7db71ba0f90ab993a584f60a387 100644 (file)
@@ -129,6 +129,8 @@ int pager_open(bool jump_to_end) {
         /* Return in the parent */
         if (dup2(fd[1], STDOUT_FILENO) < 0)
                 return log_error_errno(errno, "Failed to duplicate pager pipe: %m");
+        if (dup2(fd[1], STDERR_FILENO) < 0)
+                return log_error_errno(errno, "Failed to duplicate pager pipe: %m");
 
         safe_close_pair(fd);
         return 1;
@@ -141,6 +143,11 @@ void pager_close(void) {
 
         /* Inform pager that we are done */
         fclose(stdout);
+        stdout = NULL;
+
+        fclose(stderr);
+        stderr = NULL;
+
         kill(pager_pid, SIGCONT);
         (void) wait_for_terminate(pager_pid, NULL);
         pager_pid = 0;