static bool arg_global = false;
static bool arg_immediate = false;
static bool arg_no_block = false;
+static bool arg_no_pager = false;
static bool arg_no_wtmp = false;
static bool arg_no_sync = false;
static bool arg_no_wall = false;
" pending\n"
" -q --quiet Suppress output\n"
" --no-block Do not wait until operation finished\n"
+ " --no-pager Do not pipe output into a pager.\n"
" --system Connect to system manager\n"
" --user Connect to user service manager\n"
" --order When generating graph for dot, show only order\n"
ARG_SYSTEM,
ARG_GLOBAL,
ARG_NO_BLOCK,
+ ARG_NO_PAGER,
ARG_NO_WALL,
ARG_ORDER,
ARG_REQUIRE,
{ "system", no_argument, NULL, ARG_SYSTEM },
{ "global", no_argument, NULL, ARG_GLOBAL },
{ "no-block", no_argument, NULL, ARG_NO_BLOCK },
+ { "no-pager", no_argument, NULL, ARG_NO_PAGER },
{ "no-wall", no_argument, NULL, ARG_NO_WALL },
{ "quiet", no_argument, NULL, 'q' },
{ "order", no_argument, NULL, ARG_ORDER },
arg_no_block = true;
break;
+ case ARG_NO_PAGER:
+ arg_no_pager = true;
+ break;
+
case ARG_NO_WALL:
arg_no_wall = true;
break;
return 0;
}
+static void pager_open(void) {
+ pid_t pid;
+ int fd[2];
+ const char *pager;
+
+ if (!on_tty() || arg_no_pager)
+ return;
+
+ if ((pager = getenv("PAGER")))
+ if (!*pager || streq(pager, "cat"))
+ return;
+
+ if (pipe(fd) < 0) {
+ log_error("Failed to create pager pipe: %m");
+ return;
+ }
+
+ pid = fork();
+ if (pid < 0) {
+ log_error("Failed to fork pager: %m");
+ close_pipe(fd);
+ return;
+ }
+
+ /* The original process turns into the PAGER */
+ if (pid != 0) {
+
+ dup2(fd[0], STDIN_FILENO);
+ close_pipe(fd);
+
+ if (!getenv("LESS"))
+ setenv("LESS", "FRSX", 0);
+
+ if (pager) {
+ execlp(pager, pager, NULL);
+ execl("/bin/sh", "sh", "-c", pager, NULL);
+ } else {
+ execlp("sensible-pager", "sensible-pager", NULL);
+ execlp("less", "less", NULL);
+ execlp("more", "more", NULL);
+ }
+
+ log_error("Unable to execute pager: %m");
+ _exit(EXIT_FAILURE);
+ }
+
+ /* Return in the child */
+ if (dup2(fd[1], STDOUT_FILENO) < 0)
+ log_error("Failed to duplicate pager pipe: %m");
+
+ close_pipe(fd);
+}
+
int main(int argc, char*argv[]) {
int r, retval = EXIT_FAILURE;
DBusConnection *bus = NULL;
goto finish;
}
+ pager_open();
+
/* /sbin/runlevel doesn't need to communicate via D-Bus, so
* let's shortcut this */
if (arg_action == ACTION_RUNLEVEL) {