X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fpath-lookup.c;h=bed9175e3f1e47e37ea781ecffa8c146b1f57ed6;hp=fff930469ca0ec6b9431f9e81c0a51ade8a6f928;hb=b636465bc0190448f960791cd059c4dd1fa37717;hpb=2b583ce6576d4a074ce6f1570b3e60b65c64ae7d diff --git a/src/path-lookup.c b/src/path-lookup.c index fff930469..bed9175e3 100644 --- a/src/path-lookup.c +++ b/src/path-lookup.c @@ -53,6 +53,22 @@ int user_config_home(char **config_home) { } static char** user_dirs(void) { + const char * const config_unit_paths[] = { + "/run/systemd/user", + USER_CONFIG_UNIT_PATH, + "/etc/systemd/user", + NULL + }; + + const char * const data_unit_paths[] = { + "/usr/local/lib/systemd/user", + "/usr/local/share/systemd/user", + USER_DATA_UNIT_PATH, + "/usr/lib/systemd/user", + "/usr/share/systemd/user", + NULL + }; + const char *home, *e; char *config_home = NULL, *data_home = NULL; char **config_dirs = NULL, **data_dirs = NULL; @@ -102,7 +118,9 @@ static char** user_dirs(void) { if ((e = getenv("XDG_DATA_DIRS"))) data_dirs = strv_split(e, ":"); else - data_dirs = strv_new("/usr/local/share", "/usr/share", NULL); + data_dirs = strv_new("/usr/local/share", + "/usr/share", + NULL); if (!data_dirs) goto fail; @@ -115,12 +133,14 @@ static char** user_dirs(void) { r = t; } - if (!(t = strv_merge_concat(r, config_dirs, "/systemd/user"))) - goto finish; - strv_free(r); - r = t; + if (!strv_isempty(config_dirs)) { + if (!(t = strv_merge_concat(r, config_dirs, "/systemd/user"))) + goto finish; + strv_free(r); + r = t; + } - if (!(t = strv_append(r, USER_CONFIG_UNIT_PATH))) + if (!(t = strv_merge(r, (char**) config_unit_paths))) goto fail; strv_free(r); r = t; @@ -132,12 +152,14 @@ static char** user_dirs(void) { r = t; } - if (!(t = strv_merge_concat(r, data_dirs, "/systemd/user"))) - goto fail; - strv_free(r); - r = t; + if (!strv_isempty(data_dirs)) { + if (!(t = strv_merge_concat(r, data_dirs, "/systemd/user"))) + goto fail; + strv_free(r); + r = t; + } - if (!(t = strv_append(r, USER_DATA_UNIT_PATH))) + if (!(t = strv_merge(r, (char**) data_unit_paths))) goto fail; strv_free(r); r = t; @@ -159,7 +181,7 @@ fail: goto finish; } -int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as) { +int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal) { const char *e; char *t; @@ -177,8 +199,27 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as) { strv_free(p->unit_path); if (running_as == MANAGER_USER) { - if (!(p->unit_path = user_dirs())) + + if (personal) + p->unit_path = user_dirs(); + else + p->unit_path = strv_new( + /* If you modify this you also want to modify + * systemduserunitpath= in systemd.pc.in, and + * the arrays in user_dirs() above! */ + "/run/systemd/user", + USER_CONFIG_UNIT_PATH, + "/etc/systemd/system", + "/usr/local/lib/systemd/user", + "/usr/local/share/systemd/user", + USER_DATA_UNIT_PATH, + "/usr/lib/systemd/user", + "/usr/share/systemd/user", + NULL); + + if (!p->unit_path) return -ENOMEM; + } else if (!(p->unit_path = strv_new( /* If you modify this you also want to modify @@ -186,10 +227,10 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as) { "/run/systemd/system", SYSTEM_CONFIG_UNIT_PATH, "/etc/systemd/system", - "/usr/local/share/systemd/system", - "/usr/share/systemd/system", - "/lib/systemd/system", + "/usr/local/lib/systemd/system", + "/usr/lib/systemd/system", SYSTEM_DATA_UNIT_PATH, + "/lib/systemd/system", NULL))) return -ENOMEM; } @@ -199,6 +240,7 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as) { return -ENOMEM; strv_uniq(p->unit_path); + strv_path_remove_empty(p->unit_path); if (!strv_isempty(p->unit_path)) { @@ -253,6 +295,9 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as) { strv_uniq(p->sysvinit_path); strv_uniq(p->sysvrcnd_path); + strv_path_remove_empty(p->sysvinit_path); + strv_path_remove_empty(p->sysvrcnd_path); + if (!strv_isempty(p->sysvinit_path)) { if (!(t = strv_join(p->sysvinit_path, "\n\t")))