[systemd-devel] [PATCH] [RFCv2] Add drop-in support for [Install] section

Oleksii Shevchuk alxchk at gmail.com
Sun Mar 31 04:16:45 PDT 2013


---
 src/shared/install.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 52 insertions(+), 3 deletions(-)

diff --git a/src/shared/install.c b/src/shared/install.c
index 2555a36..2f3ce7f 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -983,7 +983,51 @@ static int config_parse_user(
         return 0;
 }
 
+static int unit_file_load_dropin(
+                LookupPaths *paths,
+                InstallContext *c,
+                InstallInfo *info,
+                const char *path,
+                const ConfigTableItem items[]) {
+
+        char **p;
+
+        assert(c);
+        assert(info);
+        assert(path);
+        assert(paths);
+        assert(items);
+
+        STRV_FOREACH(p, paths->unit_path) {
+                _cleanup_strv_free_ char **files = NULL;
+                _cleanup_free_ char *t = NULL;
+                char **f;
+                int r;
+
+                t = strjoin(*p, "/", path_get_file_name(path), ".d", NULL);
+                if (!t)
+                        return log_oom();
+
+                r = conf_files_list(&files, ".conf", NULL, t, NULL);
+                if (r < 0) {
+                        log_debug("Failed to get list of configuration files: %s: %s", *p, strerror(-r));
+                        continue;
+                }
+
+                STRV_FOREACH(f, files) {
+                        r = config_parse(*f, NULL, NULL, config_item_table_lookup, (void*) items, true, info);
+                        if (r < 0) {
+                                log_error("Failed to parse drop-in %s:", *f);
+                                return r;
+                        }
+                }
+        }
+
+        return 0;
+}
+
 static int unit_file_load(
+                LookupPaths *paths,
                 InstallContext *c,
                 InstallInfo *info,
                 const char *path,
@@ -1005,6 +1049,7 @@ static int unit_file_load(
         assert(c);
         assert(info);
         assert(path);
+        assert(paths);
 
         fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|(allow_symlink ? 0 : O_NOFOLLOW));
         if (fd < 0)
@@ -1020,6 +1065,10 @@ static int unit_file_load(
         if (r < 0)
                 return r;
 
+        r = unit_file_load_dropin(paths, c, info, path, items);
+        if (r < 0)
+                return r;
+
         return
                 strv_length(info->aliases) +
                 strv_length(info->wanted_by) +
@@ -1041,7 +1090,7 @@ static int unit_file_search(
         assert(paths);
 
         if (info->path)
-                return unit_file_load(c, info, info->path, allow_symlink);
+                return unit_file_load(paths, c, info, info->path, allow_symlink);
 
         assert(info->name);
 
@@ -1056,7 +1105,7 @@ static int unit_file_search(
                 if (!path)
                         return -ENOMEM;
 
-                r = unit_file_load(c, info, path, allow_symlink);
+                r = unit_file_load(paths, c, info, path, allow_symlink);
 
                 if (r >= 0)
                         info->path = path;
@@ -1086,7 +1135,7 @@ static int unit_file_search(
                                 }
 
                                 /* let's try to load template unit */
-                                r = unit_file_load(c, info, template_path, allow_symlink);
+                                r = unit_file_load(paths, c, info, template_path, allow_symlink);
                                 if (r >= 0) {
                                         info->path = strdup(template_path);
                                         if (!info->path) {
-- 
1.8.1.2



More information about the systemd-devel mailing list