X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fpager.c;h=3fc81820e9b4de7444658197cb98bb7ee3858c9d;hp=6ea25ada65f93f2d6ee2123eedd012edb34dee84;hb=161e54f8719c4a11440d762276cbccbeb1736f8c;hpb=7e2bb92dcae6ee785ff7462aadc8c369fd93715b diff --git a/src/pager.c b/src/pager.c index 6ea25ada6..3fc81820e 100644 --- a/src/pager.c +++ b/src/pager.c @@ -20,6 +20,7 @@ ***/ #include +#include #include #include #include @@ -31,6 +32,18 @@ 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); + if (n < 0) { + log_error("Internal pager failed: %m"); + _exit(EXIT_FAILURE); + } + _exit(EXIT_SUCCESS); +} + void pager_open(void) { int fd[2]; const char *pager; @@ -39,13 +52,13 @@ void pager_open(void) { if (pager_pid > 0) return; - if (isatty(STDOUT_FILENO) <= 0) - return; - if ((pager = getenv("SYSTEMD_PAGER")) || (pager = getenv("PAGER"))) if (!*pager || streq(pager, "cat")) return; + if (isatty(STDOUT_FILENO) <= 0) + return; + /* Determine and cache number of columns before we spawn the * pager so that we get the value from the actual tty */ columns(); @@ -96,10 +109,9 @@ void pager_open(void) { execlp("less", "less", NULL); execlp("more", "more", NULL); - execlp("cat", "cat", NULL); - log_error("Unable to execute pager: %m"); - _exit(EXIT_FAILURE); + pager_fallback(); + /* not reached */ } /* Return in the parent */