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