]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
binfmt: add --cat-config
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 27 Apr 2018 07:11:59 +0000 (09:11 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 27 Apr 2018 08:06:24 +0000 (10:06 +0200)
Document --help and --version while at it.

man/systemd-binfmt.service.xml
src/binfmt/binfmt.c

index f02e8f0cb010b3e3d30af985bf2d0e3ee2bf5ac3..37ac163f079466ae83b517842fcd2a1a4ec28902 100644 (file)
@@ -8,7 +8,8 @@
 
   Copyright 2012 Lennart Poettering
 -->
-<refentry id="systemd-binfmt.service" conditional='ENABLE_BINFMT'>
+<refentry id="systemd-binfmt.service" conditional='ENABLE_BINFMT'
+    xmlns:xi="http://www.w3.org/2001/XInclude">
 
   <refentryinfo>
     <title>systemd-binfmt.service</title>
     for information about the configuration of this service.</para>
   </refsect1>
 
+  <refsect1><title>Options</title>
+    <variablelist>
+      <xi:include href="standard-options.xml" xpointer="cat-config" />
+      <xi:include href="standard-options.xml" xpointer="help" />
+      <xi:include href="standard-options.xml" xpointer="version" />
+    </variablelist>
+  </refsect1>
+
   <refsect1>
     <title>See Also</title>
     <para>
index 03c4937dac78b74ad183a5c26ac4bc0a2d232717..22296ca1643cbe3f8221d5697c7449d7ee8640a1 100644 (file)
 #include "log.h"
 #include "string-util.h"
 #include "strv.h"
+#include "terminal-util.h"
 #include "util.h"
 
-static const char conf_file_dirs[] = CONF_PATHS_NULSTR("binfmt.d");
+static char **config_dirs = CONF_PATHS_STRV("binfmt.d");
+static bool arg_cat_config = false;
 
 static int delete_rule(const char *rule) {
         _cleanup_free_ char *x = NULL, *fn = NULL;
@@ -63,7 +65,7 @@ static int apply_file(const char *path, bool ignore_enoent) {
 
         assert(path);
 
-        r = search_and_fopen_nulstr(path, "re", NULL, conf_file_dirs, &f);
+        r = search_and_fopen(path, "re", NULL, (const char**) config_dirs, &f);
         if (r < 0) {
                 if (ignore_enoent && r == -ENOENT)
                         return 0;
@@ -102,6 +104,7 @@ static void help(void) {
                "Registers binary formats.\n\n"
                "  -h --help             Show this help\n"
                "     --version          Show package version\n"
+               "     --cat-config       Show configuration files\n"
                , program_invocation_short_name);
 }
 
@@ -109,11 +112,13 @@ static int parse_argv(int argc, char *argv[]) {
 
         enum {
                 ARG_VERSION = 0x100,
+                ARG_CAT_CONFIG,
         };
 
         static const struct option options[] = {
-                { "help",      no_argument,       NULL, 'h'           },
-                { "version",   no_argument,       NULL, ARG_VERSION   },
+                { "help",       no_argument,       NULL, 'h'            },
+                { "version",    no_argument,       NULL, ARG_VERSION    },
+                { "cat-config", no_argument,       NULL, ARG_CAT_CONFIG },
                 {}
         };
 
@@ -133,6 +138,10 @@ static int parse_argv(int argc, char *argv[]) {
                 case ARG_VERSION:
                         return version();
 
+                case ARG_CAT_CONFIG:
+                        arg_cat_config = true;
+                        break;
+
                 case '?':
                         return -EINVAL;
 
@@ -140,6 +149,11 @@ static int parse_argv(int argc, char *argv[]) {
                         assert_not_reached("Unhandled option");
                 }
 
+        if (arg_cat_config && argc > optind) {
+                log_error("Positional arguments are not allowed with --cat-config");
+                return -EINVAL;
+        }
+
         return 1;
 }
 
@@ -170,12 +184,17 @@ int main(int argc, char *argv[]) {
                 _cleanup_strv_free_ char **files = NULL;
                 char **f;
 
-                r = conf_files_list_nulstr(&files, ".conf", NULL, 0, conf_file_dirs);
+                r = conf_files_list_strv(&files, ".conf", NULL, 0, (const char**) config_dirs);
                 if (r < 0) {
                         log_error_errno(r, "Failed to enumerate binfmt.d files: %m");
                         goto finish;
                 }
 
+                if (arg_cat_config) {
+                        r = cat_files(NULL, files, 0);
+                        goto finish;
+                }
+
                 /* Flush out all rules */
                 write_string_file("/proc/sys/fs/binfmt_misc/status", "-1", 0);