summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-06-28 11:21:39 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-07-06 18:38:32 +0200
commit43942e8055bb01890e725bd5f06855e48caa251e (patch)
treeb27f18e29f515d773bb7c6b998ae8a97deb63149 /src
parentstrv: make strv_split() accept empty string (diff)
downloadsystemd-43942e8055bb01890e725bd5f06855e48caa251e.tar.xz
systemd-43942e8055bb01890e725bd5f06855e48caa251e.zip
pager: split $PAGER or $SYSTEMD_PAGER and use execvp()
This makes pager_open() correctly handle e.g. PAGER=' ' or PAGER=' cat '.
Diffstat (limited to 'src')
-rw-r--r--src/basic/pager.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/basic/pager.c b/src/basic/pager.c
index f241261119..7d698666e9 100644
--- a/src/basic/pager.c
+++ b/src/basic/pager.c
@@ -43,6 +43,7 @@ _noreturn_ static void pager_fallback(void) {
int pager_open(bool no_pager, bool jump_to_end) {
_cleanup_close_pair_ int fd[2] = { -1, -1 };
+ _cleanup_strv_free_ char **pager_args = NULL;
const char *pager;
int r;
@@ -62,9 +63,15 @@ int pager_open(bool no_pager, bool jump_to_end) {
if (!pager)
pager = getenv("PAGER");
- /* If the pager is explicitly turned off, honour it */
- if (pager && STR_IN_SET(pager, "", "cat"))
- return 0;
+ if (pager) {
+ pager_args = strv_split(pager, WHITESPACE);
+ if (!pager_args)
+ return -ENOMEM;
+
+ /* If the pager is explicitly turned off, honour it */
+ if (strv_isempty(pager_args) || strv_equal(pager_args, STRV_MAKE("cat")))
+ return 0;
+ }
/* Determine and cache number of columns/lines before we spawn the pager so that we get the value from the
* actual tty */
@@ -104,10 +111,8 @@ int pager_open(bool no_pager, bool jump_to_end) {
setenv("LESSCHARSET", less_charset, 1) < 0)
_exit(EXIT_FAILURE);
- if (pager) {
- execlp(pager, pager, NULL);
- execl("/bin/sh", "sh", "-c", pager, NULL);
- }
+ if (pager_args)
+ execvp(pager_args[0], pager_args);
/* Debian's alternatives command for pagers is
* called 'pager'. Note that we do not call