summaryrefslogtreecommitdiff
path: root/src/basic/conf-files.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic/conf-files.c')
-rw-r--r--src/basic/conf-files.c51
1 files changed, 51 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,