This restores the original root handling logic that was present prior to
112cfb18 when path expansion moved to path_strv_canonicalize_absolute.
That behavior partially went away in
12ed81d9.
Alternatively all users of conf_files_list* could be updated to
concatenate the paths themselves as unit_file_query_preset did but since
no user needs the un-concatenated form that is pointless duplication.
#include "hashmap.h"
#include "conf-files.h"
#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;
_cleanup_closedir_ DIR *dir = NULL;
- 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;
if (!dir) {
if (errno == ENOENT)
return 0;
return -ENOMEM;
STRV_FOREACH(p, dirs) {
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;
if (r == -ENOMEM) {
hashmap_free_free(fh);
return r;
int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name) {
_cleanup_strv_free_ char **files = NULL;
int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name) {
_cleanup_strv_free_ char **files = NULL;
int r;
assert(scope >= 0);
int r;
assert(scope >= 0);
- STRV_FOREACH(i, files) {
- _cleanup_free_ char *buf = NULL;
+ STRV_FOREACH(p, files) {
_cleanup_fclose_ FILE *f;
_cleanup_fclose_ FILE *f;
- const char *p;
-
- if (root_dir)
- p = buf = strjoin(root_dir, "/", *i, NULL);
- else
- p = *i;
if (!f) {
if (errno == ENOENT)
continue;
if (!f) {
if (errno == ENOENT)
continue;