mirror of
https://github.com/systemd/systemd.git
synced 2025-02-23 13:57:33 +03:00
analyze: add --root option for cat-config
This commit is contained in:
parent
3c51c62616
commit
46d8646a9f
@ -367,6 +367,13 @@ NAutoVTs=8
|
|||||||
generators enabled will generally result in some warnings.</para></listitem>
|
generators enabled will generally result in some warnings.</para></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>--root=<replaceable>PATH</replaceable></option></term>
|
||||||
|
|
||||||
|
<listitem><para>With <command>cat-files</command>, show config files underneath
|
||||||
|
the specified root path <replaceable>PATH</replaceable>.</para></listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<xi:include href="user-system-options.xml" xpointer="host" />
|
<xi:include href="user-system-options.xml" xpointer="host" />
|
||||||
<xi:include href="user-system-options.xml" xpointer="machine" />
|
<xi:include href="user-system-options.xml" xpointer="machine" />
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ static const char *arg_host = NULL;
|
|||||||
static UnitFileScope arg_scope = UNIT_FILE_SYSTEM;
|
static UnitFileScope arg_scope = UNIT_FILE_SYSTEM;
|
||||||
static bool arg_man = true;
|
static bool arg_man = true;
|
||||||
static bool arg_generators = false;
|
static bool arg_generators = false;
|
||||||
|
static const char *arg_root = NULL;
|
||||||
|
|
||||||
struct boot_times {
|
struct boot_times {
|
||||||
usec_t firmware_time;
|
usec_t firmware_time;
|
||||||
@ -1329,7 +1330,7 @@ static int cat_config(int argc, char *argv[], void *userdata) {
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = conf_files_cat(*arg);
|
r = conf_files_cat(arg_root, *arg);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -1688,6 +1689,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
ARG_VERSION = 0x100,
|
ARG_VERSION = 0x100,
|
||||||
ARG_ORDER,
|
ARG_ORDER,
|
||||||
ARG_REQUIRE,
|
ARG_REQUIRE,
|
||||||
|
ARG_ROOT,
|
||||||
ARG_SYSTEM,
|
ARG_SYSTEM,
|
||||||
ARG_USER,
|
ARG_USER,
|
||||||
ARG_GLOBAL,
|
ARG_GLOBAL,
|
||||||
@ -1704,6 +1706,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
{ "version", no_argument, NULL, ARG_VERSION },
|
{ "version", no_argument, NULL, ARG_VERSION },
|
||||||
{ "order", no_argument, NULL, ARG_ORDER },
|
{ "order", no_argument, NULL, ARG_ORDER },
|
||||||
{ "require", no_argument, NULL, ARG_REQUIRE },
|
{ "require", no_argument, NULL, ARG_REQUIRE },
|
||||||
|
{ "root", required_argument, NULL, ARG_ROOT },
|
||||||
{ "system", no_argument, NULL, ARG_SYSTEM },
|
{ "system", no_argument, NULL, ARG_SYSTEM },
|
||||||
{ "user", no_argument, NULL, ARG_USER },
|
{ "user", no_argument, NULL, ARG_USER },
|
||||||
{ "global", no_argument, NULL, ARG_GLOBAL },
|
{ "global", no_argument, NULL, ARG_GLOBAL },
|
||||||
@ -1732,6 +1735,10 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
case ARG_VERSION:
|
case ARG_VERSION:
|
||||||
return version();
|
return version();
|
||||||
|
|
||||||
|
case ARG_ROOT:
|
||||||
|
arg_root = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
case ARG_SYSTEM:
|
case ARG_SYSTEM:
|
||||||
arg_scope = UNIT_FILE_SYSTEM;
|
arg_scope = UNIT_FILE_SYSTEM;
|
||||||
break;
|
break;
|
||||||
@ -1825,6 +1832,11 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (arg_root && !streq_ptr(argv[optind], "cat-config")) {
|
||||||
|
log_error("Option --root is only supported for cat-config right now.");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return 1; /* work to do */
|
return 1; /* work to do */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,8 +294,9 @@ int conf_files_list_with_replacement(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int conf_files_cat(const char *name) {
|
int conf_files_cat(const char *root, const char *name) {
|
||||||
_cleanup_strv_free_ char **dirs = NULL, **files = NULL;
|
_cleanup_strv_free_ char **dirs = NULL, **files = NULL;
|
||||||
|
_cleanup_free_ char *path = NULL;
|
||||||
const char *dir;
|
const char *dir;
|
||||||
char **t;
|
char **t;
|
||||||
int r;
|
int r;
|
||||||
@ -307,19 +308,21 @@ int conf_files_cat(const char *name) {
|
|||||||
return log_error("Failed to build directory list: %m");
|
return log_error("Failed to build directory list: %m");
|
||||||
}
|
}
|
||||||
|
|
||||||
r = conf_files_list_strv(&files, ".conf", NULL, 0, (const char* const*) dirs);
|
r = conf_files_list_strv(&files, ".conf", root, 0, (const char* const*) dirs);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to query file list: %m");
|
return log_error_errno(r, "Failed to query file list: %m");
|
||||||
|
|
||||||
name = strjoina("/etc/", name);
|
path = path_join(root, "/etc", name);
|
||||||
|
if (!path)
|
||||||
|
return log_oom();
|
||||||
|
|
||||||
if (DEBUG_LOGGING) {
|
if (DEBUG_LOGGING) {
|
||||||
log_debug("Looking for configuration in:");
|
log_debug("Looking for configuration in:");
|
||||||
log_debug(" %s", name);
|
log_debug(" %s", path);
|
||||||
STRV_FOREACH(t, dirs)
|
STRV_FOREACH(t, dirs)
|
||||||
log_debug(" %s/*.conf", *t);
|
log_debug(" %s/*.conf", *t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* show */
|
/* show */
|
||||||
return cat_files(name, files, CAT_FLAGS_MAIN_FILE_OPTIONAL);
|
return cat_files(path, files, CAT_FLAGS_MAIN_FILE_OPTIONAL);
|
||||||
}
|
}
|
||||||
|
@ -23,4 +23,4 @@ int conf_files_list_with_replacement(
|
|||||||
const char *replacement,
|
const char *replacement,
|
||||||
char ***files,
|
char ***files,
|
||||||
char **replace_file);
|
char **replace_file);
|
||||||
int conf_files_cat(const char *name);
|
int conf_files_cat(const char *root, const char *name);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user