dcavalca / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone
Blob Blame History Raw
From b5f15b581d886a332de50512c0fe75d1acc0c1ee Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Tue, 17 Jun 2014 01:56:44 +0200
Subject: [PATCH] conf-files: fix when for --root= logic

This is based on parts of similar patches from Michael Marineau and
Lukas Nykryn, but simply uses strappenda3().

(cherry picked from commit cebed5005b5ede17fc52ab50c054fca73bc938b8)

Related: #1111199
---
 src/shared/conf-files.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/shared/conf-files.c b/src/shared/conf-files.c
index 3d5b1df..4ec8bed 100644
--- a/src/shared/conf-files.c
+++ b/src/shared/conf-files.c
@@ -37,10 +37,20 @@
 #include "hashmap.h"
 #include "conf-files.h"
 
-static int files_add(Hashmap *h, const char *dirpath, const char *suffix) {
+static int files_add(Hashmap *h, const char *dirpath, const char *suffix, const char *root) {
         _cleanup_closedir_ DIR *dir = NULL;
 
-        dir = opendir(dirpath);
+        assert(dirpath);
+        assert(suffix);
+
+        if (isempty(root))
+                dir = opendir(dirpath);
+        else {
+                const char *p;
+
+                p = strappenda3(root, "/", dirpath);
+                dir = opendir(p);
+        }
         if (!dir) {
                 if (errno == ENOENT)
                         return 0;
@@ -108,7 +118,7 @@ static int conf_files_list_strv_internal(char ***strv, const char *suffix, const
                 return -ENOMEM;
 
         STRV_FOREACH(p, dirs) {
-                r = files_add(fh, *p, suffix);
+                r = files_add(fh, *p, suffix, root);
                 if (r == -ENOMEM) {
                         hashmap_free_free(fh);
                         return r;