mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-06 12:58:22 +03:00
binfmt: add --cat-config
Document --help and --version while at it.
This commit is contained in:
parent
46d8646a9f
commit
6aaab70f0c
@ -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>
|
||||
|
@ -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 },
|
||||
{ "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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user