chiark / gitweb /
conf-files: fix when for --root= logic
authorLennart Poettering <lennart@poettering.net>
Mon, 16 Jun 2014 23:56:44 +0000 (01:56 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 17 Jun 2014 00:43:44 +0000 (02:43 +0200)
This is based on parts of similar patches from Michael Marineau and
Lukas Nykrin, but simply uses strappenda3().

src/shared/conf-files.c

index 52017821834f4663b540371e34561056e51af81d..59bc8ceed937abbe21c6965b19a2c0da6b5e344b 100644 (file)
 #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;