summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2011-09-26 23:02:56 +0200
committerMichal Schmidt <mschmidt@redhat.com>2011-09-27 11:57:24 +0200
commit4a8e40ebd0938850d326c33a3d563c6cd44d47b4 (patch)
tree9fee9a03c3429d52fdfdfcae755d7c51ea0b328d /src
parent7c83341a593160e2b4739bdb8a1ad76b21bbdf9e (diff)
pager: add a trivial internal pager
In the very unlikely scenario where none of the external pagers is available, use an internal implementation to pass stdin to stdout. Don't bother with trying 'cat', because it's no more useful than the internal pager. https://bugzilla.redhat.com/show_bug.cgi?id=713707
Diffstat (limited to 'src')
-rw-r--r--src/pager.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/pager.c b/src/pager.c
index be284da96..6e2bb4901 100644
--- a/src/pager.c
+++ b/src/pager.c
@@ -20,6 +20,7 @@
***/
#include <sys/types.h>
+#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
@@ -31,6 +32,18 @@
static pid_t pager_pid = 0;
+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;
@@ -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 */