From 6a7c676c54eb205d80f124eeb66c84df3c54d174 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 28 Aug 2015 00:11:49 +0200 Subject: pager: port fallback pager to use copy_bytes() --- src/shared/pager.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/shared/pager.c') diff --git a/src/shared/pager.c b/src/shared/pager.c index 13f03e798b..a5454e377d 100644 --- a/src/shared/pager.c +++ b/src/shared/pager.c @@ -31,18 +31,16 @@ #include "macro.h" #include "terminal-util.h" #include "signal-util.h" +#include "copy.h" static pid_t pager_pid = 0; noreturn static void pager_fallback(void) { - ssize_t n; - - do { - n = splice(STDIN_FILENO, NULL, STDOUT_FILENO, NULL, 64*1024, 0); - } while (n > 0); + int r; - if (n < 0) { - log_error_errno(errno, "Internal pager failed: %m"); + r = copy_bytes(STDIN_FILENO, STDOUT_FILENO, (off_t) -1, false); + if (r < 0) { + log_error_errno(r, "Internal pager failed: %m"); _exit(EXIT_FAILURE); } -- cgit v1.2.3-54-g00ecf From 8b5264aa65ea8f631990174a6f705d5a0d8e95fc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 28 Aug 2015 00:13:34 +0200 Subject: pager: also redirect stderr 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 | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/shared/pager.c') diff --git a/src/shared/pager.c b/src/shared/pager.c index a5454e377d..85f8fa5b39 100644 --- a/src/shared/pager.c +++ b/src/shared/pager.c @@ -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; -- cgit v1.2.3-54-g00ecf