summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/shared/conf-files.c16
-rw-r--r--src/shared/install.c13
2 files changed, 9 insertions, 20 deletions
diff --git a/src/shared/conf-files.c b/src/shared/conf-files.c
index 44e137e84c..64ce8a0e57 100644
--- a/src/shared/conf-files.c
+++ b/src/shared/conf-files.c
@@ -37,20 +37,16 @@
#include "hashmap.h"
#include "conf-files.h"
-static int files_add(Hashmap *h, const char *dirpath, const char *suffix, const char *root) {
+static int files_add(Hashmap *h, const char *root, const char *path, const char *suffix) {
_cleanup_closedir_ DIR *dir = NULL;
+ char *dirpath;
- assert(dirpath);
+ assert(path);
assert(suffix);
- if (isempty(root))
- dir = opendir(dirpath);
- else {
- const char *p;
+ dirpath = strappenda(root ? root : "", path);
- p = strappenda3(root, "/", dirpath);
- dir = opendir(p);
- }
+ dir = opendir(dirpath);
if (!dir) {
if (errno == ENOENT)
return 0;
@@ -118,7 +114,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, root);
+ r = files_add(fh, root, *p, suffix);
if (r == -ENOMEM) {
hashmap_free_free(fh);
return r;
diff --git a/src/shared/install.c b/src/shared/install.c
index 4f7179309e..190c554347 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1776,7 +1776,7 @@ UnitFileState unit_file_get_state(
int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name) {
_cleanup_strv_free_ char **files = NULL;
- char **i;
+ char **p;
int r;
assert(scope >= 0);
@@ -1804,17 +1804,10 @@ int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char
if (r < 0)
return r;
- STRV_FOREACH(i, files) {
- _cleanup_free_ char *buf = NULL;
+ STRV_FOREACH(p, files) {
_cleanup_fclose_ FILE *f;
- const char *p;
-
- if (root_dir)
- p = buf = strjoin(root_dir, "/", *i, NULL);
- else
- p = *i;
- f = fopen(p, "re");
+ f = fopen(*p, "re");
if (!f) {
if (errno == ENOENT)
continue;