|
|
9fc0f6 |
From b5f15b581d886a332de50512c0fe75d1acc0c1ee Mon Sep 17 00:00:00 2001
|
|
|
9fc0f6 |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
9fc0f6 |
Date: Tue, 17 Jun 2014 01:56:44 +0200
|
|
|
9fc0f6 |
Subject: [PATCH] conf-files: fix when for --root= logic
|
|
|
9fc0f6 |
|
|
|
9fc0f6 |
This is based on parts of similar patches from Michael Marineau and
|
|
|
9fc0f6 |
Lukas Nykryn, but simply uses strappenda3().
|
|
|
9fc0f6 |
|
|
|
9fc0f6 |
(cherry picked from commit cebed5005b5ede17fc52ab50c054fca73bc938b8)
|
|
|
9fc0f6 |
|
|
|
9fc0f6 |
Related: #1111199
|
|
|
9fc0f6 |
---
|
|
|
9fc0f6 |
src/shared/conf-files.c | 16 +++++++++++++---
|
|
|
9fc0f6 |
1 file changed, 13 insertions(+), 3 deletions(-)
|
|
|
9fc0f6 |
|
|
|
9fc0f6 |
diff --git a/src/shared/conf-files.c b/src/shared/conf-files.c
|
|
|
9fc0f6 |
index 3d5b1df..4ec8bed 100644
|
|
|
9fc0f6 |
--- a/src/shared/conf-files.c
|
|
|
9fc0f6 |
+++ b/src/shared/conf-files.c
|
|
|
9fc0f6 |
@@ -37,10 +37,20 @@
|
|
|
9fc0f6 |
#include "hashmap.h"
|
|
|
9fc0f6 |
#include "conf-files.h"
|
|
|
9fc0f6 |
|
|
|
9fc0f6 |
-static int files_add(Hashmap *h, const char *dirpath, const char *suffix) {
|
|
|
9fc0f6 |
+static int files_add(Hashmap *h, const char *dirpath, const char *suffix, const char *root) {
|
|
|
9fc0f6 |
_cleanup_closedir_ DIR *dir = NULL;
|
|
|
9fc0f6 |
|
|
|
9fc0f6 |
- dir = opendir(dirpath);
|
|
|
9fc0f6 |
+ assert(dirpath);
|
|
|
9fc0f6 |
+ assert(suffix);
|
|
|
9fc0f6 |
+
|
|
|
9fc0f6 |
+ if (isempty(root))
|
|
|
9fc0f6 |
+ dir = opendir(dirpath);
|
|
|
9fc0f6 |
+ else {
|
|
|
9fc0f6 |
+ const char *p;
|
|
|
9fc0f6 |
+
|
|
|
9fc0f6 |
+ p = strappenda3(root, "/", dirpath);
|
|
|
9fc0f6 |
+ dir = opendir(p);
|
|
|
9fc0f6 |
+ }
|
|
|
9fc0f6 |
if (!dir) {
|
|
|
9fc0f6 |
if (errno == ENOENT)
|
|
|
9fc0f6 |
return 0;
|
|
|
9fc0f6 |
@@ -108,7 +118,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);
|
|
|
9fc0f6 |
+ r = files_add(fh, *p, suffix, root);
|
|
|
9fc0f6 |
if (r == -ENOMEM) {
|
|
|
9fc0f6 |
hashmap_free_free(fh);
|
|
|
9fc0f6 |
return r;
|