]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
binfmt: add --tldr
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 15 Oct 2023 16:34:54 +0000 (18:34 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 24 Oct 2023 16:32:18 +0000 (18:32 +0200)
man/systemd-binfmt.service.xml
src/binfmt/binfmt.c

index b52b58494e54bd6c7a10b48ad9c574b50e3ea531..15453fae2928f21e51f596e9c913610156af9574 100644 (file)
@@ -52,6 +52,7 @@
       </varlistentry>
 
       <xi:include href="standard-options.xml" xpointer="cat-config" />
+      <xi:include href="standard-options.xml" xpointer="tldr" />
       <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 fa3d6b0e26df90c9bad3ec0af08d69b826dc9358..1b34638ff9bbe5ce575cd5243da4dda209d4179d 100644 (file)
@@ -24,7 +24,7 @@
 #include "string-util.h"
 #include "strv.h"
 
-static bool arg_cat_config = false;
+static CatFlags arg_cat_flags = CAT_CONFIG_OFF;
 static PagerFlags arg_pager_flags = 0;
 static bool arg_unregister = false;
 
@@ -106,6 +106,12 @@ static int apply_file(const char *filename, bool ignore_enoent) {
         return r;
 }
 
+static int cat_config(char **files) {
+        pager_open(arg_pager_flags);
+
+        return cat_files(NULL, files, arg_cat_flags);
+}
+
 static int help(void) {
         _cleanup_free_ char *link = NULL;
         int r;
@@ -119,6 +125,7 @@ static int help(void) {
                "  -h --help             Show this help\n"
                "     --version          Show package version\n"
                "     --cat-config       Show configuration files\n"
+               "     --tldr             Show non-comment parts of configuration\n"
                "     --no-pager         Do not pipe output into a pager\n"
                "     --unregister       Unregister all existing entries\n"
                "\nSee the %s for details.\n",
@@ -132,6 +139,7 @@ static int parse_argv(int argc, char *argv[]) {
         enum {
                 ARG_VERSION = 0x100,
                 ARG_CAT_CONFIG,
+                ARG_TLDR,
                 ARG_NO_PAGER,
                 ARG_UNREGISTER,
         };
@@ -140,6 +148,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "help",       no_argument, NULL, 'h'            },
                 { "version",    no_argument, NULL, ARG_VERSION    },
                 { "cat-config", no_argument, NULL, ARG_CAT_CONFIG },
+                { "tldr",       no_argument, NULL, ARG_TLDR       },
                 { "no-pager",   no_argument, NULL, ARG_NO_PAGER   },
                 { "unregister", no_argument, NULL, ARG_UNREGISTER },
                 {}
@@ -161,7 +170,11 @@ static int parse_argv(int argc, char *argv[]) {
                         return version();
 
                 case ARG_CAT_CONFIG:
-                        arg_cat_config = true;
+                        arg_cat_flags = CAT_CONFIG_ON;
+                        break;
+
+                case ARG_TLDR:
+                        arg_cat_flags = CAT_TLDR;
                         break;
 
                 case ARG_NO_PAGER:
@@ -179,9 +192,9 @@ static int parse_argv(int argc, char *argv[]) {
                         assert_not_reached();
                 }
 
-        if ((arg_unregister || arg_cat_config) && argc > optind)
+        if ((arg_unregister || arg_cat_flags != CAT_CONFIG_OFF) && argc > optind)
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                       "Positional arguments are not allowed with --cat-config or --unregister");
+                                       "Positional arguments are not allowed with --cat-config/--tldr or --unregister.");
 
         return 1;
 }
@@ -229,11 +242,8 @@ static int run(int argc, char *argv[]) {
                 if (r < 0)
                         return log_error_errno(r, "Failed to enumerate binfmt.d files: %m");
 
-                if (arg_cat_config) {
-                        pager_open(arg_pager_flags);
-
-                        return cat_files(NULL, files, /* flags= */ 0);
-                }
+                if (arg_cat_flags != CAT_CONFIG_OFF)
+                        return cat_config(files);
 
                 r = binfmt_mounted_warn();
                 if (r <= 0)