***/
#include <sys/types.h>
+#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.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);
+ 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;
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();
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 */