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