This is a follow-up of a issue I raised last August but we didn't fix it at all and it stayed in limbo until I got it by this issue this week.
Currently, unit search path lists is getting cleaned (where paths containing no files are removed from the list ) when systemd is initialized, but before generators are run (and the only time when /run/systemd/system could be populated is by generators). After discussing with Lennart and Kay on irc about this issue, it appears the solution is to defer the unit search list after generators have been run. Attached patch implement those fixes. -- Frederic Crozat <[email protected]> SUSE
>From 78ff3a3ed814fb4f35a9c64866bba467afdaa69a Mon Sep 17 00:00:00 2001 From: Frederic Crozat <[email protected]> Date: Tue, 14 Feb 2012 16:52:52 +0100 Subject: [PATCH] defer checking if paths are empty after running generators. --- 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
_______________________________________________ systemd-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/systemd-devel
