chiark / gitweb /
analyze: add --root option for cat-config
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 27 Apr 2018 06:55:16 +0000 (08:55 +0200)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
src/basic/conf-files.c
src/basic/conf-files.h

index aec4d9ddb8bbd431ade2e12d7a3c5652616d2070..a168be8b8c259b861031221b85ad6a0969d0fbdb 100644 (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);
 }
index 7eb8739ee135b08e358c9090d92f7cf6b9f4d85a..2dd1b272caa8130e551079856a277d279540a65a 100644 (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);