diff options
Diffstat (limited to 'src/binfmt/binfmt.c')
-rw-r--r-- | src/binfmt/binfmt.c | 29 |
1 files changed, 24 insertions, 5 deletions
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); |