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