summaryrefslogtreecommitdiff
path: root/src/shared/pager.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-10-18 23:34:37 +0200
committerLennart Poettering <lennart@poettering.net>2012-10-18 23:35:44 +0200
commitf89a3b6f5bf695186e7b9e6cc63993b1272e7569 (patch)
tree8478df8b23a18b3a8f2968522df0928cede5ec92 /src/shared/pager.c
parentcd4b13e0bfe9281a0d2c0c3bef1c589d0684950b (diff)
journalctl: unify ellipsation handling between journalctl and systemctl
Diffstat (limited to 'src/shared/pager.c')
-rw-r--r--src/shared/pager.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/shared/pager.c b/src/shared/pager.c
index 36b409c070..6799787e85 100644
--- a/src/shared/pager.c
+++ b/src/shared/pager.c
@@ -44,20 +44,21 @@ _noreturn_ static void pager_fallback(void) {
_exit(EXIT_SUCCESS);
}
-bool pager_open(void) {
+int pager_open(void) {
int fd[2];
const char *pager;
pid_t parent_pid;
+ int r;
if (pager_pid > 0)
- return false;
+ return 1;
if ((pager = getenv("SYSTEMD_PAGER")) || (pager = getenv("PAGER")))
if (!*pager || streq(pager, "cat"))
- return false;
+ return 0;
if (isatty(STDOUT_FILENO) <= 0)
- return false;
+ return 0;
/* Determine and cache number of columns before we spawn the
* pager so that we get the value from the actual tty */
@@ -65,16 +66,17 @@ bool pager_open(void) {
if (pipe(fd) < 0) {
log_error("Failed to create pager pipe: %m");
- return false;
+ return -errno;
}
parent_pid = getpid();
pager_pid = fork();
if (pager_pid < 0) {
+ r = -errno;
log_error("Failed to fork pager: %m");
close_pipe(fd);
- return false;
+ return r;
}
/* In the child start the pager */
@@ -117,11 +119,11 @@ bool pager_open(void) {
/* Return in the parent */
if (dup2(fd[1], STDOUT_FILENO) < 0) {
log_error("Failed to duplicate pager pipe: %m");
- return false;
+ return -errno;
}
close_pipe(fd);
- return true;
+ return 1;
}
void pager_close(void) {
@@ -135,3 +137,7 @@ void pager_close(void) {
wait_for_terminate(pager_pid, NULL);
pager_pid = 0;
}
+
+bool pager_have(void) {
+ return pager_pid > 0;
+}