From: Zbigniew Jędrzejewski-Szmek Date: Fri, 27 Apr 2018 06:55:16 +0000 (+0200) Subject: analyze: add --root option for cat-config X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=fae965b26bc77f90cb9b028519ac51337d91ebc1;p=elogind.git analyze: add --root option for cat-config --- diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c index aec4d9ddb..a168be8b8 100644 --- a/src/basic/conf-files.c +++ b/src/basic/conf-files.c @@ -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); } diff --git a/src/basic/conf-files.h b/src/basic/conf-files.h index 7eb8739ee..2dd1b272c 100644 --- a/src/basic/conf-files.h +++ b/src/basic/conf-files.h @@ -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);