]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
binfmt,sysctl,sysuers,tmpfiles: add auto-paging for --cat-config commands
authorLennart Poettering <lennart@poettering.net>
Tue, 12 Jun 2018 13:37:53 +0000 (15:37 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 13 Jun 2018 12:20:03 +0000 (14:20 +0200)
The output of these commands is really long, and already enriched with
color. Let's add auto-paging to make this easier to digest.

man/systemd-binfmt.service.xml
man/systemd-sysctl.service.xml
man/systemd-sysusers.xml
man/systemd-tmpfiles.xml
src/binfmt/binfmt.c
src/sysctl/sysctl.c
src/sysusers/sysusers.c
src/tmpfiles/tmpfiles.c

index 37ac163f079466ae83b517842fcd2a1a4ec28902..9de0a50c538291e28921e2619d71627a2c7f10a6 100644 (file)
@@ -56,6 +56,7 @@
   <refsect1><title>Options</title>
     <variablelist>
       <xi:include href="standard-options.xml" xpointer="cat-config" />
+      <xi:include href="standard-options.xml" xpointer="no-pager" />
       <xi:include href="standard-options.xml" xpointer="help" />
       <xi:include href="standard-options.xml" xpointer="version" />
     </variablelist>
index 5df310cff561b047b1c3ffb3ef372d4515440ad4..a5faabe1d348b908e75dbb3334997e5d0cf72443 100644 (file)
@@ -80,6 +80,7 @@
       </varlistentry>
 
       <xi:include href="standard-options.xml" xpointer="cat-config" />
+      <xi:include href="standard-options.xml" xpointer="no-pager" />
       <xi:include href="standard-options.xml" xpointer="help" />
       <xi:include href="standard-options.xml" xpointer="version" />
 
index ea119fe375297f52b298c18f0f28aa42202abd12..e862498e80a54935c07f061b61339eb2e6c83f30 100644 (file)
       </varlistentry>
 
       <xi:include href="standard-options.xml" xpointer="cat-config" />
+      <xi:include href="standard-options.xml" xpointer="no-pager" />
       <xi:include href="standard-options.xml" xpointer="help" />
       <xi:include href="standard-options.xml" xpointer="version" />
     </variablelist>
index 3ef3fa28706f9829b1349f5fa402d8e8a67f4145..df9dac3548ed0b6dfc4bf05f3aa9c6eea486f677 100644 (file)
       </varlistentry>
 
       <xi:include href="standard-options.xml" xpointer="cat-config" />
+      <xi:include href="standard-options.xml" xpointer="no-pager" />
       <xi:include href="standard-options.xml" xpointer="help" />
       <xi:include href="standard-options.xml" xpointer="version" />
     </variablelist>
index 0eb9e4601462817bd0106a180c0454303161c84a..f4af4bef26747842199836ee098734f84717f4e6 100644 (file)
 #include "fd-util.h"
 #include "fileio.h"
 #include "log.h"
+#include "pager.h"
 #include "string-util.h"
 #include "strv.h"
 #include "terminal-util.h"
 #include "util.h"
 
 static bool arg_cat_config = false;
+static bool arg_no_pager = false;
 
 static int delete_rule(const char *rule) {
         _cleanup_free_ char *x = NULL, *fn = NULL;
@@ -104,6 +106,7 @@ static void help(void) {
                "  -h --help             Show this help\n"
                "     --version          Show package version\n"
                "     --cat-config       Show configuration files\n"
+               "     --no-pager         Do not pipe output into a pager\n"
                , program_invocation_short_name);
 }
 
@@ -112,12 +115,14 @@ static int parse_argv(int argc, char *argv[]) {
         enum {
                 ARG_VERSION = 0x100,
                 ARG_CAT_CONFIG,
+                ARG_NO_PAGER,
         };
 
         static const struct option options[] = {
-                { "help",       no_argument,       NULL, 'h'            },
-                { "version",    no_argument,       NULL, ARG_VERSION    },
-                { "cat-config", no_argument,       NULL, ARG_CAT_CONFIG },
+                { "help",       no_argument, NULL, 'h'            },
+                { "version",    no_argument, NULL, ARG_VERSION    },
+                { "cat-config", no_argument, NULL, ARG_CAT_CONFIG },
+                { "no-pager",   no_argument, NULL, ARG_NO_PAGER   },
                 {}
         };
 
@@ -141,6 +146,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_cat_config = true;
                         break;
 
+                case ARG_NO_PAGER:
+                        arg_no_pager = true;
+                        break;
+
                 case '?':
                         return -EINVAL;
 
@@ -190,6 +199,8 @@ int main(int argc, char *argv[]) {
                 }
 
                 if (arg_cat_config) {
+                        (void) pager_open(arg_no_pager, false);
+
                         r = cat_files(NULL, files, 0);
                         goto finish;
                 }
@@ -205,5 +216,7 @@ int main(int argc, char *argv[]) {
         }
 
 finish:
+        pager_close();
+
         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 }
index 5489cb96b7a098bf4b4a84955d8a88e17236f9a6..a719ea1f9d8a915164d8c3d8d727055f36f265d0 100644 (file)
@@ -19,6 +19,7 @@
 #include "fileio.h"
 #include "hashmap.h"
 #include "log.h"
+#include "pager.h"
 #include "path-util.h"
 #include "string-util.h"
 #include "strv.h"
@@ -28,6 +29,7 @@
 
 static char **arg_prefixes = NULL;
 static bool arg_cat_config = false;
+static bool arg_no_pager = false;
 
 static int apply_all(OrderedHashmap *sysctl_options) {
         char *property, *value;
@@ -170,6 +172,7 @@ static void help(void) {
                "     --version          Show package version\n"
                "     --cat-config       Show configuration files\n"
                "     --prefix=PATH      Only apply rules with the specified prefix\n"
+               "     --no-pager         Do not pipe output into a pager\n"
                , program_invocation_short_name);
 }
 
@@ -179,6 +182,7 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_VERSION = 0x100,
                 ARG_CAT_CONFIG,
                 ARG_PREFIX,
+                ARG_NO_PAGER,
         };
 
         static const struct option options[] = {
@@ -186,6 +190,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "version",    no_argument,       NULL, ARG_VERSION    },
                 { "cat-config", no_argument,       NULL, ARG_CAT_CONFIG },
                 { "prefix",     required_argument, NULL, ARG_PREFIX     },
+                { "no-pager",   no_argument,       NULL, ARG_NO_PAGER   },
                 {}
         };
 
@@ -231,6 +236,10 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
                 }
 
+                case ARG_NO_PAGER:
+                        arg_no_pager = true;
+                        break;
+
                 case '?':
                         return -EINVAL;
 
@@ -287,6 +296,8 @@ int main(int argc, char *argv[]) {
                 }
 
                 if (arg_cat_config) {
+                        (void) pager_open(arg_no_pager, false);
+
                         r = cat_files(NULL, files, 0);
                         goto finish;
                 }
@@ -303,6 +314,8 @@ int main(int argc, char *argv[]) {
                 r = k;
 
 finish:
+        pager_close();
+
         ordered_hashmap_free_free_free(sysctl_options);
         strv_free(arg_prefixes);
 
index 7caa97e27b9982514ffbcc16224c84ebff06cead..ccb3fca8f2fb5f0ae519a98ed5184ad882c284d0 100644 (file)
 #include "copy.h"
 #include "def.h"
 #include "fd-util.h"
-#include "fs-util.h"
 #include "fileio-label.h"
 #include "format-util.h"
+#include "fs-util.h"
 #include "hashmap.h"
+#include "pager.h"
 #include "path-util.h"
 #include "selinux-util.h"
 #include "smack-util.h"
@@ -35,6 +36,7 @@ typedef enum ItemType {
         ADD_MEMBER = 'm',
         ADD_RANGE = 'r',
 } ItemType;
+
 typedef struct Item {
         ItemType type;
 
@@ -65,6 +67,7 @@ static char *arg_root = NULL;
 static bool arg_cat_config = false;
 static const char *arg_replace = NULL;
 static bool arg_inline = false;
+static bool arg_no_pager = false;
 
 static OrderedHashmap *users = NULL, *groups = NULL;
 static OrderedHashmap *todo_uids = NULL, *todo_gids = NULL;
@@ -1764,6 +1767,8 @@ static int cat_config(void) {
         if (r < 0)
                 return r;
 
+        (void) pager_open(arg_no_pager, false);
+
         return cat_files(NULL, files, 0);
 }
 
@@ -1776,6 +1781,7 @@ static void help(void) {
                "     --root=PATH            Operate on an alternate filesystem root\n"
                "     --replace=PATH         Treat arguments as replacement for PATH\n"
                "     --inline               Treat arguments as configuration lines\n"
+               "     --no-pager             Do not pipe output into a pager\n"
                , program_invocation_short_name);
 }
 
@@ -1787,6 +1793,7 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_ROOT,
                 ARG_REPLACE,
                 ARG_INLINE,
+                ARG_NO_PAGER,
         };
 
         static const struct option options[] = {
@@ -1796,6 +1803,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "root",       required_argument, NULL, ARG_ROOT       },
                 { "replace",    required_argument, NULL, ARG_REPLACE    },
                 { "inline",     no_argument,       NULL, ARG_INLINE     },
+                { "no-pager",   no_argument,       NULL, ARG_NO_PAGER   },
                 {}
         };
 
@@ -1839,6 +1847,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_inline = true;
                         break;
 
+                case ARG_NO_PAGER:
+                        arg_no_pager = true;
+                        break;
+
                 case '?':
                         return -EINVAL;
 
@@ -1999,6 +2011,8 @@ int main(int argc, char *argv[]) {
                 log_error_errno(r, "Failed to write files: %m");
 
 finish:
+        pager_close();
+
         ordered_hashmap_free_with_destructor(groups, item_free);
         ordered_hashmap_free_with_destructor(users, item_free);
 
index 6bfa44f076130238ae9d2d0bb642c1b449ba998d..183e98b3c16e9fb747178b6064241f53a572811c 100644 (file)
@@ -48,6 +48,7 @@
 #include "missing.h"
 #include "mkdir.h"
 #include "mount-util.h"
+#include "pager.h"
 #include "parse-util.h"
 #include "path-lookup.h"
 #include "path-util.h"
@@ -156,6 +157,7 @@ static bool arg_create = false;
 static bool arg_clean = false;
 static bool arg_remove = false;
 static bool arg_boot = false;
+static bool arg_no_pager = false;
 
 static char **arg_include_prefixes = NULL;
 static char **arg_exclude_prefixes = NULL;
@@ -2511,6 +2513,7 @@ static void help(void) {
                "     --exclude-prefix=PATH  Ignore rules with the specified prefix\n"
                "     --root=PATH            Operate on an alternate filesystem root\n"
                "     --replace=PATH         Treat arguments as replacement for PATH\n"
+               "     --no-pager             Do not pipe output into a pager\n"
                , program_invocation_short_name);
 }
 
@@ -2528,6 +2531,7 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_EXCLUDE_PREFIX,
                 ARG_ROOT,
                 ARG_REPLACE,
+                ARG_NO_PAGER,
         };
 
         static const struct option options[] = {
@@ -2543,6 +2547,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "exclude-prefix", required_argument,   NULL, ARG_EXCLUDE_PREFIX },
                 { "root",           required_argument,   NULL, ARG_ROOT           },
                 { "replace",        required_argument,   NULL, ARG_REPLACE        },
+                { "no-pager",       no_argument,         NULL, ARG_NO_PAGER       },
                 {}
         };
 
@@ -2612,6 +2617,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_replace = optarg;
                         break;
 
+                case ARG_NO_PAGER:
+                        arg_no_pager = true;
+                        break;
+
                 case '?':
                         return -EINVAL;
 
@@ -2801,6 +2810,8 @@ int main(int argc, char *argv[]) {
         }
 
         if (arg_cat_config) {
+                (void) pager_open(arg_no_pager, false);
+
                 r = cat_config(config_dirs, argv + optind);
                 goto finish;
         }
@@ -2847,6 +2858,8 @@ int main(int argc, char *argv[]) {
         }
 
 finish:
+        pager_close();
+
         ordered_hashmap_free_with_destructor(items, item_array_free);
         ordered_hashmap_free_with_destructor(globs, item_array_free);