analyze: add --root option for cat-config

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-04-27 10:06:24 +02:00
parent 3c51c62616
commit 46d8646a9f
4 changed files with 29 additions and 7 deletions
+8 -5
View File
@@ -294,8 +294,9 @@ int conf_files_list_with_replacement(
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_free_ char *path = NULL;
const char *dir;
char **t;
int r;
@@ -307,19 +308,21 @@ int conf_files_cat(const char *name) {
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)
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) {
log_debug("Looking for configuration in:");
log_debug(" %s", name);
log_debug(" %s", path);
STRV_FOREACH(t, dirs)
log_debug(" %s/*.conf", *t);
}
/* show */
return cat_files(name, files, CAT_FLAGS_MAIN_FILE_OPTIONAL);
return cat_files(path, files, CAT_FLAGS_MAIN_FILE_OPTIONAL);
}
+1 -1
View File
@@ -23,4 +23,4 @@ int conf_files_list_with_replacement(
const char *replacement,
char ***files,
char **replace_file);
int conf_files_cat(const char *name);
int conf_files_cat(const char *root, const char *name);