diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-04-27 09:11:59 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-04-27 10:06:24 +0200 |
commit | 6aaab70f0c7af9a529a2433ad39fe9169883a391 (patch) | |
tree | 2f1f6547b4e035424f5d4d8659e234d00af5f439 | |
parent | 46d8646a9fd637b8911ac032cb2a760407221f9a (diff) | |
download | systemd-6aaab70f0c7af9a529a2433ad39fe9169883a391.tar.gz |
binfmt: add --cat-config
Document --help and --version while at it.
-rw-r--r-- | man/systemd-binfmt.service.xml | 11 | ||||
-rw-r--r-- | src/binfmt/binfmt.c | 29 |
2 files changed, 34 insertions, 6 deletions
diff --git a/man/systemd-binfmt.service.xml b/man/systemd-binfmt.service.xml index f02e8f0cb0..37ac163f07 100644 --- a/man/systemd-binfmt.service.xml +++ b/man/systemd-binfmt.service.xml @@ -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> @@ -52,6 +53,14 @@ 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> diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c index 03c4937dac..22296ca164 100644 --- a/src/binfmt/binfmt.c +++ b/src/binfmt/binfmt.c @@ -21,9 +21,11 @@ #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); |