chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
pager: add -M to $LESS to make the bottom line nicer
[elogind.git]
/
src
/
shared
/
pager.c
diff --git
a/src/shared/pager.c
b/src/shared/pager.c
index 36b409c07031932843c5994209d8daa3bed44fc9..8dddf24f4c7816ba7e739016563f4c92b282cca2 100644
(file)
--- a/
src/shared/pager.c
+++ b/
src/shared/pager.c
@@
-44,20
+44,21
@@
_noreturn_ static void pager_fallback(void) {
_exit(EXIT_SUCCESS);
}
_exit(EXIT_SUCCESS);
}
-
bool pager_open(voi
d) {
+
int pager_open(bool jump_to_en
d) {
int fd[2];
const char *pager;
pid_t parent_pid;
int fd[2];
const char *pager;
pid_t parent_pid;
+ int r;
if (pager_pid > 0)
if (pager_pid > 0)
- return
false
;
+ return
1
;
if ((pager = getenv("SYSTEMD_PAGER")) || (pager = getenv("PAGER")))
if (!*pager || streq(pager, "cat"))
if ((pager = getenv("SYSTEMD_PAGER")) || (pager = getenv("PAGER")))
if (!*pager || streq(pager, "cat"))
- return
false
;
+ return
0
;
- if (
isatty(STDOUT_FILENO) <= 0
)
- return
false
;
+ if (
!on_tty()
)
+ return
0
;
/* Determine and cache number of columns before we spawn the
* pager so that we get the value from the actual tty */
/* 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");
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) {
}
parent_pid = getpid();
pager_pid = fork();
if (pager_pid < 0) {
+ r = -errno;
log_error("Failed to fork pager: %m");
close_pipe(fd);
log_error("Failed to fork pager: %m");
close_pipe(fd);
- return
false
;
+ return
r
;
}
/* In the child start the pager */
}
/* In the child start the pager */
@@
-83,7
+85,10
@@
bool pager_open(void) {
dup2(fd[0], STDIN_FILENO);
close_pipe(fd);
dup2(fd[0], STDIN_FILENO);
close_pipe(fd);
- setenv("LESS", "FRSX", 0);
+ if (jump_to_end)
+ setenv("LESS", "FRSXMK+G", 1);
+ else
+ setenv("LESS", "FRSXMK", 1);
/* Make sure the pager goes away when the parent dies */
if (prctl(PR_SET_PDEATHSIG, SIGTERM) < 0)
/* Make sure the pager goes away when the parent dies */
if (prctl(PR_SET_PDEATHSIG, SIGTERM) < 0)
@@
-117,11
+122,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 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);
}
close_pipe(fd);
- return
true
;
+ return
1
;
}
void pager_close(void) {
}
void pager_close(void) {
@@
-135,3
+140,7
@@
void pager_close(void) {
wait_for_terminate(pager_pid, NULL);
pager_pid = 0;
}
wait_for_terminate(pager_pid, NULL);
pager_pid = 0;
}
+
+bool pager_have(void) {
+ return pager_pid > 0;
+}