84b277
From b5f15b581d886a332de50512c0fe75d1acc0c1ee Mon Sep 17 00:00:00 2001
84b277
From: Lennart Poettering <lennart@poettering.net>
84b277
Date: Tue, 17 Jun 2014 01:56:44 +0200
84b277
Subject: [PATCH] conf-files: fix when for --root= logic
84b277
84b277
This is based on parts of similar patches from Michael Marineau and
84b277
Lukas Nykryn, but simply uses strappenda3().
84b277
84b277
(cherry picked from commit cebed5005b5ede17fc52ab50c054fca73bc938b8)
84b277
84b277
Related: #1111199
84b277
---
84b277
 src/shared/conf-files.c | 16 +++++++++++++---
84b277
 1 file changed, 13 insertions(+), 3 deletions(-)
84b277
84b277
diff --git a/src/shared/conf-files.c b/src/shared/conf-files.c
84b277
index 3d5b1df..4ec8bed 100644
84b277
--- a/src/shared/conf-files.c
84b277
+++ b/src/shared/conf-files.c
84b277
@@ -37,10 +37,20 @@
84b277
 #include "hashmap.h"
84b277
 #include "conf-files.h"
84b277
 
84b277
-static int files_add(Hashmap *h, const char *dirpath, const char *suffix) {
84b277
+static int files_add(Hashmap *h, const char *dirpath, const char *suffix, const char *root) {
84b277
         _cleanup_closedir_ DIR *dir = NULL;
84b277
 
84b277
-        dir = opendir(dirpath);
84b277
+        assert(dirpath);
84b277
+        assert(suffix);
84b277
+
84b277
+        if (isempty(root))
84b277
+                dir = opendir(dirpath);
84b277
+        else {
84b277
+                const char *p;
84b277
+
84b277
+                p = strappenda3(root, "/", dirpath);
84b277
+                dir = opendir(p);
84b277
+        }
84b277
         if (!dir) {
84b277
                 if (errno == ENOENT)
84b277
                         return 0;
84b277
@@ -108,7 +118,7 @@ static int conf_files_list_strv_internal(char ***strv, const char *suffix, const
84b277
                 return -ENOMEM;
84b277
 
84b277
         STRV_FOREACH(p, dirs) {
84b277
-                r = files_add(fh, *p, suffix);
84b277
+                r = files_add(fh, *p, suffix, root);
84b277
                 if (r == -ENOMEM) {
84b277
                         hashmap_free_free(fh);
84b277
                         return r;