]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/dropin.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / shared / dropin.c
index 3ed98f5e0b717ff5791d68163a4e230858abf111..a16f436bede7e41a1938510a23f6be2a3a6d0385 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
   This file is part of systemd.
 
@@ -148,16 +149,14 @@ static int unit_file_find_dirs(
                 const char *suffix,
                 char ***dirs) {
 
-        _cleanup_free_ char *path = NULL;
+        char *path;
         int r;
 
         assert(unit_path);
         assert(name);
         assert(suffix);
 
-        path = strjoin(unit_path, "/", name, suffix);
-        if (!path)
-                return log_oom();
+        path = strjoina(unit_path, "/", name, suffix);
 
         if (!unit_path_cache || set_get(unit_path_cache, path)) {
                 r = unit_file_find_dir(original_root, path, dirs);
@@ -166,22 +165,15 @@ static int unit_file_find_dirs(
         }
 
         if (unit_name_is_valid(name, UNIT_NAME_INSTANCE)) {
-                _cleanup_free_ char *template = NULL, *p = NULL;
                 /* Also try the template dir */
 
+                _cleanup_free_ char *template = NULL;
+
                 r = unit_name_template(name, &template);
                 if (r < 0)
                         return log_error_errno(r, "Failed to generate template from unit name: %m");
 
-                p = strjoin(unit_path, "/", template, suffix);
-                if (!p)
-                        return log_oom();
-
-                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 unit_file_find_dirs(original_root, unit_path_cache, unit_path, template, suffix, dirs);
         }
 
         return 0;
@@ -194,27 +186,27 @@ int unit_file_find_dropin_paths(
                 const char *dir_suffix,
                 const char *file_suffix,
                 Set *names,
-                char ***paths) {
+                char ***ret) {
 
-        _cleanup_strv_free_ char **dirs = NULL, **ans = NULL;
+        _cleanup_strv_free_ char **dirs = NULL;
         Iterator i;
         char *t, **p;
         int r;
 
-        assert(paths);
+        assert(ret);
 
         SET_FOREACH(t, names, i)
                 STRV_FOREACH(p, lookup_path)
                         unit_file_find_dirs(original_root, unit_path_cache, *p, t, dir_suffix, &dirs);
 
-        if (strv_isempty(dirs))
+        if (strv_isempty(dirs)) {
+                *ret = NULL;
                 return 0;
+        }
 
-        r = conf_files_list_strv(&ans, file_suffix, NULL, (const char**) dirs);
+        r = conf_files_list_strv(ret, file_suffix, NULL, 0, (const char**) dirs);
         if (r < 0)
-                return log_warning_errno(r, "Failed to sort the list of configuration files: %m");
+                return log_warning_errno(r, "Failed to create the list of configuration files: %m");
 
-        *paths = ans;
-        ans = NULL;
         return 1;
 }