From: David Tardon Date: Thu, 17 May 2018 13:45:37 +0000 (+0200) Subject: inhibit: use pager for systemd-inhibit --list X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=8094890c09f56ae20d4b6923e9fce29c28d66aea;p=elogind.git inhibit: use pager for systemd-inhibit --list --- diff --git a/src/login/inhibit.c b/src/login/inhibit.c index f3a209bfb..aabfdbde4 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -18,6 +18,7 @@ #include "bus-util.h" #include "fd-util.h" #include "format-util.h" +//#include "pager.h" #include "process-util.h" #include "signal-util.h" #include "strv.h" @@ -31,6 +32,7 @@ static const char* arg_what = "idle:sleep:shutdown"; static const char* arg_who = NULL; static const char* arg_why = "Unknown reason"; static const char* arg_mode = NULL; +static bool arg_no_pager = false; static enum { ACTION_INHIBIT, @@ -72,6 +74,8 @@ static int print_inhibitors(sd_bus *bus, sd_bus_error *error) { unsigned n = 0; int r; + (void) pager_open(arg_no_pager, false); + r = sd_bus_call_method( bus, "org.freedesktop.login1", @@ -124,6 +128,7 @@ static void help(void) { "Execute a process while inhibiting shutdown/sleep/idle.\n\n" " -h --help Show this help\n" " --version Show package version\n" + " --no-pager Do not pipe output into a pager\n" " --what=WHAT Operations to inhibit, colon separated list of:\n" " shutdown, sleep, idle, handle-power-key,\n" " handle-suspend-key, handle-hibernate-key,\n" @@ -144,6 +149,7 @@ static int parse_argv(int argc, char *argv[]) { ARG_WHY, ARG_MODE, ARG_LIST, + ARG_NO_PAGER, }; static const struct option options[] = { @@ -154,6 +160,7 @@ static int parse_argv(int argc, char *argv[]) { { "why", required_argument, NULL, ARG_WHY }, { "mode", required_argument, NULL, ARG_MODE }, { "list", no_argument, NULL, ARG_LIST }, + { "no-pager", no_argument, NULL, ARG_NO_PAGER }, {} }; @@ -193,6 +200,10 @@ static int parse_argv(int argc, char *argv[]) { arg_action = ACTION_LIST; break; + case ARG_NO_PAGER: + arg_no_pager = true; + break; + case '?': return -EINVAL; @@ -235,6 +246,7 @@ int main(int argc, char *argv[]) { if (arg_action == ACTION_LIST) { r = print_inhibitors(bus, &error); + pager_close(); if (r < 0) { log_error("Failed to list inhibitors: %s", bus_error_message(&error, -r)); return EXIT_FAILURE;