1cd37a9
From 806e59a1e136764e1deb676eaa2666eee603af9f Mon Sep 17 00:00:00 2001
1cd37a9
From: Michael Marineau <michael.marineau@coreos.com>
1cd37a9
Date: Thu, 19 Jun 2014 19:07:04 -0700
1cd37a9
Subject: [PATCH] conf-files: include root in returned file paths
1cd37a9
1cd37a9
This restores the original root handling logic that was present prior to
1cd37a9
112cfb18 when path expansion moved to path_strv_canonicalize_absolute.
1cd37a9
That behavior partially went away in 12ed81d9.
1cd37a9
1cd37a9
Alternatively all users of conf_files_list* could be updated to
1cd37a9
concatenate the paths themselves as unit_file_query_preset did but since
1cd37a9
no user needs the un-concatenated form that is pointless duplication.
1cd37a9
1cd37a9
(cherry picked from commit cba2ef02722114da2b730d57f1e3bb43013d8921)
1cd37a9
1cd37a9
Conflicts:
1cd37a9
	src/shared/install.c
1cd37a9
1cd37a9
(cherry picked from commit 084c41bc148e0a7b0eeee614d9e0acc9aaae6b0d)
1cd37a9
---
1cd37a9
 src/shared/conf-files.c | 16 ++++++----------
1cd37a9
 src/shared/install.c    |  6 +++---
1cd37a9
 2 files changed, 9 insertions(+), 13 deletions(-)
1cd37a9
1cd37a9
diff --git a/src/shared/conf-files.c b/src/shared/conf-files.c
1cd37a9
index 4ec8bed..fc5f1fe 100644
1cd37a9
--- a/src/shared/conf-files.c
1cd37a9
+++ b/src/shared/conf-files.c
1cd37a9
@@ -37,20 +37,16 @@
1cd37a9
 #include "hashmap.h"
1cd37a9
 #include "conf-files.h"
1cd37a9
 
1cd37a9
-static int files_add(Hashmap *h, const char *dirpath, const char *suffix, const char *root) {
1cd37a9
+static int files_add(Hashmap *h, const char *root, const char *path, const char *suffix) {
1cd37a9
         _cleanup_closedir_ DIR *dir = NULL;
1cd37a9
+        char *dirpath;
1cd37a9
 
1cd37a9
-        assert(dirpath);
1cd37a9
+        assert(path);
1cd37a9
         assert(suffix);
1cd37a9
 
1cd37a9
-        if (isempty(root))
1cd37a9
-                dir = opendir(dirpath);
1cd37a9
-        else {
1cd37a9
-                const char *p;
1cd37a9
+        dirpath = strappenda(root ? root : "", path);
1cd37a9
 
1cd37a9
-                p = strappenda3(root, "/", dirpath);
1cd37a9
-                dir = opendir(p);
1cd37a9
-        }
1cd37a9
+        dir = opendir(dirpath);
1cd37a9
         if (!dir) {
1cd37a9
                 if (errno == ENOENT)
1cd37a9
                         return 0;
1cd37a9
@@ -118,7 +114,7 @@ static int conf_files_list_strv_internal(char ***strv, const char *suffix, const
1cd37a9
                 return -ENOMEM;
1cd37a9
 
1cd37a9
         STRV_FOREACH(p, dirs) {
1cd37a9
-                r = files_add(fh, *p, suffix, root);
1cd37a9
+                r = files_add(fh, root, *p, suffix);
1cd37a9
                 if (r == -ENOMEM) {
1cd37a9
                         hashmap_free_free(fh);
1cd37a9
                         return r;
1cd37a9
diff --git a/src/shared/install.c b/src/shared/install.c
1cd37a9
index 86a05a4..f40be79 100644
1cd37a9
--- a/src/shared/install.c
1cd37a9
+++ b/src/shared/install.c
1cd37a9
@@ -1763,7 +1763,7 @@ UnitFileState unit_file_get_state(
1cd37a9
 
1cd37a9
 int unit_file_query_preset(UnitFileScope scope, const char *name) {
1cd37a9
         _cleanup_strv_free_ char **files = NULL;
1cd37a9
-        char **i;
1cd37a9
+        char **p;
1cd37a9
         int r;
1cd37a9
 
1cd37a9
         assert(scope >= 0);
1cd37a9
@@ -1791,10 +1791,10 @@ int unit_file_query_preset(UnitFileScope scope, const char *name) {
1cd37a9
         if (r < 0)
1cd37a9
                 return r;
1cd37a9
 
1cd37a9
-        STRV_FOREACH(i, files) {
1cd37a9
+        STRV_FOREACH(p, files) {
1cd37a9
                 _cleanup_fclose_ FILE *f;
1cd37a9
 
1cd37a9
-                f = fopen(*i, "re");
1cd37a9
+                f = fopen(*p, "re");
1cd37a9
                 if (!f) {
1cd37a9
                         if (errno == ENOENT)
1cd37a9
                                 continue;