summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/shared/dropin.c85
-rw-r--r--src/shared/dropin.h11
2 files changed, 25 insertions, 71 deletions
diff --git a/src/shared/dropin.c b/src/shared/dropin.c
index 3944ccec44..3917eb8f23 100644
--- a/src/shared/dropin.c
+++ b/src/shared/dropin.c
@@ -117,17 +117,12 @@ int write_drop_in_format(const char *dir, const char *unit, unsigned level,
return write_drop_in(dir, unit, level, name, p);
}
-static int iterate_dir(
- const char *path,
+static int unit_file_find_dir(
const char *original_root,
- UnitDependency dependency,
- dependency_consumer_t consumer,
- void *arg,
- char ***strv) {
+ const char *path,
+ char ***dirs) {
_cleanup_free_ char *chased = NULL;
- _cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
int r;
assert(path);
@@ -137,52 +132,21 @@ static int iterate_dir(
return log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING,
r, "Failed to canonicalize path %s: %m", path);
- /* The config directories are special, since the order of the
- * drop-ins matters */
- if (dependency < 0) {
- r = strv_push(strv, chased);
- if (r < 0)
- return log_oom();
-
- chased = NULL;
- return 0;
- }
-
- assert(consumer);
-
- d = opendir(chased);
- if (!d) {
- if (errno == ENOENT)
- return 0;
-
- return log_warning_errno(errno, "Failed to open directory %s: %m", path);
- }
-
- FOREACH_DIRENT(de, d, return log_warning_errno(errno, "Failed to read directory %s: %m", path)) {
- _cleanup_free_ char *f = NULL;
-
- f = strjoin(path, "/", de->d_name);
- if (!f)
- return log_oom();
-
- r = consumer(dependency, de->d_name, f, arg);
- if (r < 0)
- return r;
- }
+ r = strv_push(dirs, chased);
+ if (r < 0)
+ return log_oom();
+ chased = NULL;
return 0;
}
-static int unit_file_process_dir(
+static int unit_file_find_dirs(
const char *original_root,
Set *unit_path_cache,
const char *unit_path,
const char *name,
const char *suffix,
- UnitDependency dependency,
- dependency_consumer_t consumer,
- void *arg,
- char ***strv) {
+ char ***dirs) {
_cleanup_free_ char *path = NULL;
int r;
@@ -195,8 +159,11 @@ static int unit_file_process_dir(
if (!path)
return log_oom();
- if (!unit_path_cache || set_get(unit_path_cache, path))
- (void) iterate_dir(path, original_root, dependency, consumer, arg, strv);
+ if (!unit_path_cache || set_get(unit_path_cache, path)) {
+ r = unit_file_find_dir(original_root, path, dirs);
+ if (r < 0)
+ return r;
+ }
if (unit_name_is_valid(name, UNIT_NAME_INSTANCE)) {
_cleanup_free_ char *template = NULL, *p = NULL;
@@ -210,8 +177,11 @@ static int unit_file_process_dir(
if (!p)
return log_oom();
- if (!unit_path_cache || set_get(unit_path_cache, p))
- (void) iterate_dir(p, original_root, dependency, consumer, arg, strv);
+ if (!unit_path_cache || set_get(unit_path_cache, p)) {
+ r = unit_file_find_dir(original_root, p, dirs);
+ if (r < 0)
+ return r;
+ }
}
return 0;
@@ -226,26 +196,21 @@ int unit_file_find_dropin_paths(
Set *names,
char ***paths) {
- _cleanup_strv_free_ char **strv = NULL, **ans = NULL;
+ _cleanup_strv_free_ char **dirs = NULL, **ans = NULL;
Iterator i;
- char *t;
+ char *t, **p;
int r;
assert(paths);
- SET_FOREACH(t, names, i) {
- char **p;
-
+ SET_FOREACH(t, names, i)
STRV_FOREACH(p, lookup_path)
- unit_file_process_dir(original_root, unit_path_cache,
- *p, t, dir_suffix,
- _UNIT_DEPENDENCY_INVALID, NULL, NULL, &strv);
- }
+ unit_file_find_dirs(original_root, unit_path_cache, *p, t, dir_suffix, &dirs);
- if (strv_isempty(strv))
+ if (strv_isempty(dirs))
return 0;
- r = conf_files_list_strv(&ans, file_suffix, NULL, (const char**) strv);
+ r = conf_files_list_strv(&ans, file_suffix, NULL, (const char**) dirs);
if (r < 0)
return log_warning_errno(r, "Failed to sort the list of configuration files: %m");
diff --git a/src/shared/dropin.h b/src/shared/dropin.h
index 22cd2fa229..a2b8cdce61 100644
--- a/src/shared/dropin.h
+++ b/src/shared/dropin.h
@@ -33,17 +33,6 @@ int write_drop_in(const char *dir, const char *unit, unsigned level,
int write_drop_in_format(const char *dir, const char *unit, unsigned level,
const char *name, const char *format, ...) _printf_(5, 6);
-/**
- * This callback will be called for each directory entry @entry,
- * with @filepath being the full path to the entry.
- *
- * If return value is negative, loop will be aborted.
- */
-typedef int (*dependency_consumer_t)(UnitDependency dependency,
- const char *entry,
- const char* filepath,
- void *arg);
-
int unit_file_find_dropin_paths(
const char *original_root,
char **lookup_path,