[PATCH] defer checking if paths are empty after running generators.

Frederic Crozat fcrozat at suse.com
Tue Feb 14 07:52:52 PST 2012


---
 TODO              |    3 ---
 src/manager.c     |    2 ++
 src/path-lookup.c |   52 ++++++++++++++++++++++++++++++++++------------------
 src/path-lookup.h |    2 ++
 4 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/TODO b/TODO
index 46d4c04..239653a 100644
--- a/TODO
+++ b/TODO
@@ -21,9 +21,6 @@ Bugfixes:
 
 Features:
 
-* support units generated by a generator and placed in /run/systemd/system/; the directory is
-  currently ignored because it is empty before the generatores are executed
-
 * let 'systemctl reboot' called as non-root talk to logind instead of systemd, to get polkit
   system policy in the loop of privilege checking, so normal users can possibly use /sbin/reboot
 
diff --git a/src/manager.c b/src/manager.c
index 74bd740..18527aa 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -550,6 +550,8 @@ static void manager_build_unit_path_cache(Manager *m) {
 
         assert(m);
 
+        lookup_paths_cleanup(&m->lookup_paths, m->running_as);
+
         set_free_free(m->unit_path_cache);
 
         if (!(m->unit_path_cache = set_new(string_hash_func, string_compare_func))) {
diff --git a/src/path-lookup.c b/src/path-lookup.c
index 93fdf63..382fec4 100644
--- a/src/path-lookup.c
+++ b/src/path-lookup.c
@@ -183,7 +183,6 @@ fail:
 
 int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal) {
         const char *e;
-        char *t;
 
         assert(p);
 
@@ -242,16 +241,7 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal
                         return -ENOMEM;
 
         strv_uniq(p->unit_path);
-        strv_path_remove_empty(p->unit_path);
-
-        if (!strv_isempty(p->unit_path)) {
-
-                if (!(t = strv_join(p->unit_path, "\n\t")))
-                        return -ENOMEM;
-                log_debug("Looking for unit files in:\n\t%s", t);
-                free(t);
-        } else {
-                log_debug("Ignoring unit files.");
+        if (strv_isempty(p->unit_path)) {
                 strv_free(p->unit_path);
                 p->unit_path = NULL;
         }
@@ -300,6 +290,39 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal
                 strv_path_remove_empty(p->sysvinit_path);
                 strv_path_remove_empty(p->sysvrcnd_path);
 
+                if (strv_isempty(p->sysvinit_path)) {
+                        strv_free(p->sysvinit_path);
+                        p->sysvinit_path = NULL;
+                }
+
+                if (strv_isempty(p->sysvrcnd_path)) {
+                        strv_free(p->sysvrcnd_path);
+                        p->sysvrcnd_path = NULL;
+                }
+#endif
+        }
+
+        return 0;
+}
+
+void lookup_paths_cleanup(LookupPaths *p, ManagerRunningAs running_as) {
+        char *t;
+
+        strv_path_remove_empty(p->unit_path);
+
+        if (!strv_isempty(p->unit_path)) {
+                if (!(t = strv_join(p->unit_path, "\n\t")))
+                        return -ENOMEM;
+                log_debug("Looking for unit files in:\n\t%s", t);
+                free(t);
+        } else {
+                log_debug("Ignoring unit files.");
+                strv_free(p->unit_path);
+                p->unit_path = NULL;
+        }
+
+        if (running_as == MANAGER_SYSTEM) {
+#ifdef HAVE_SYSV_COMPAT
                 if (!strv_isempty(p->sysvinit_path)) {
 
                         if (!(t = strv_join(p->sysvinit_path, "\n\t")))
@@ -309,10 +332,7 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal
                         free(t);
                 } else {
                         log_debug("Ignoring SysV init scripts.");
-                        strv_free(p->sysvinit_path);
-                        p->sysvinit_path = NULL;
                 }
-
                 if (!strv_isempty(p->sysvrcnd_path)) {
 
                         if (!(t = strv_join(p->sysvrcnd_path, "\n\t")))
@@ -322,15 +342,11 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal
                         free(t);
                 } else {
                         log_debug("Ignoring SysV rcN.d links.");
-                        strv_free(p->sysvrcnd_path);
-                        p->sysvrcnd_path = NULL;
                 }
 #else
                 log_debug("Disabled SysV init scripts and rcN.d links support");
 #endif
         }
-
-        return 0;
 }
 
 void lookup_paths_free(LookupPaths *p) {
diff --git a/src/path-lookup.h b/src/path-lookup.h
index fc2887d..28e4579 100644
--- a/src/path-lookup.h
+++ b/src/path-lookup.h
@@ -35,6 +35,8 @@ typedef struct LookupPaths {
 int user_config_home(char **config_home);
 
 int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal);
+
+void lookup_paths_cleanup(LookupPaths *p, ManagerRunningAs running_as);
 void lookup_paths_free(LookupPaths *p);
 
 #endif
-- 
1.7.7


--=-/q0iQCFKB37ctVd/KqKM--



More information about the systemd-devel mailing list