ryantimwilson / rpms / systemd

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