summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/basic/conf-files.c51
-rw-r--r--src/basic/conf-files.h3
2 files changed, 54 insertions, 0 deletions
diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c
index 9e7428a3c8..c31fe79ebd 100644
--- a/src/basic/conf-files.c
+++ b/src/basic/conf-files.c
@@ -180,6 +180,41 @@ int conf_files_list_strv(
return copy_and_sort_files_from_hashmap(fh, ret);
}
+int conf_files_list_strv_at(
+ char ***ret,
+ const char *suffix,
+ int rfd,
+ unsigned flags,
+ const char * const *dirs) {
+
+ _cleanup_hashmap_free_ Hashmap *fh = NULL;
+ _cleanup_set_free_ Set *masked = NULL;
+ int r;
+
+ assert(rfd >= 0 || rfd == AT_FDCWD);
+ assert(ret);
+
+ STRV_FOREACH(p, dirs) {
+ _cleanup_closedir_ DIR *dir = NULL;
+ _cleanup_free_ char *path = NULL;
+
+ r = chase_and_opendirat(rfd, *p, CHASE_AT_RESOLVE_IN_ROOT, &path, &dir);
+ if (r < 0) {
+ if (r != -ENOENT)
+ log_debug_errno(r, "Failed to chase and open directory '%s', ignoring: %m", *p);
+ continue;
+ }
+
+ r = files_add(dir, path, &fh, &masked, suffix, flags);
+ if (r == -ENOMEM)
+ return r;
+ if (r < 0)
+ log_debug_errno(r, "Failed to search for files in '%s', ignoring: %m", path);
+ }
+
+ return copy_and_sort_files_from_hashmap(fh, ret);
+}
+
int conf_files_insert(char ***strv, const char *root, char **dirs, const char *path) {
/* Insert a path into strv, at the place honouring the usual sorting rules:
* - we first compare by the basename
@@ -252,6 +287,10 @@ int conf_files_list(char ***ret, const char *suffix, const char *root, unsigned
return conf_files_list_strv(ret, suffix, root, flags, STRV_MAKE_CONST(dir));
}
+int conf_files_list_at(char ***ret, const char *suffix, int rfd, unsigned flags, const char *dir) {
+ return conf_files_list_strv_at(ret, suffix, rfd, flags, STRV_MAKE_CONST(dir));
+}
+
int conf_files_list_nulstr(char ***ret, const char *suffix, const char *root, unsigned flags, const char *dirs) {
_cleanup_strv_free_ char **d = NULL;
@@ -264,6 +303,18 @@ int conf_files_list_nulstr(char ***ret, const char *suffix, const char *root, un
return conf_files_list_strv(ret, suffix, root, flags, (const char**) d);
}
+int conf_files_list_nulstr_at(char ***ret, const char *suffix, int rfd, unsigned flags, const char *dirs) {
+ _cleanup_strv_free_ char **d = NULL;
+
+ assert(ret);
+
+ d = strv_split_nulstr(dirs);
+ if (!d)
+ return -ENOMEM;
+
+ return conf_files_list_strv_at(ret, suffix, rfd, flags, (const char**) d);
+}
+
int conf_files_list_with_replacement(
const char *root,
char **config_dirs,
diff --git a/src/basic/conf-files.h b/src/basic/conf-files.h
index 7774ed7054..547c2fc137 100644
--- a/src/basic/conf-files.h
+++ b/src/basic/conf-files.h
@@ -12,8 +12,11 @@ enum {
};
int conf_files_list(char ***ret, const char *suffix, const char *root, unsigned flags, const char *dir);
+int conf_files_list_at(char ***ret, const char *suffix, int rfd, unsigned flags, const char *dir);
int conf_files_list_strv(char ***ret, const char *suffix, const char *root, unsigned flags, const char* const* dirs);
+int conf_files_list_strv_at(char ***ret, const char *suffix, int rfd, unsigned flags, const char * const *dirs);
int conf_files_list_nulstr(char ***ret, const char *suffix, const char *root, unsigned flags, const char *dirs);
+int conf_files_list_nulstr_at(char ***ret, const char *suffix, int rfd, unsigned flags, const char *dirs);
int conf_files_insert(char ***strv, const char *root, char **dirs, const char *path);
int conf_files_list_with_replacement(
const char *root,