chiark / gitweb /
path-lookup: make inclusion of user private units optional
[elogind.git] / src / path-lookup.c
index fff930469ca0ec6b9431f9e81c0a51ade8a6f928..84a9859254eebcd263072b7efe193fd92cc4ce94 100644 (file)
@@ -102,7 +102,11 @@ 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/local/lib",
+                                     "/usr/share",
+                                     "/usr/lib",
+                                     NULL);
 
         if (!data_dirs)
                 goto fail;
@@ -159,7 +163,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 +181,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 +209,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 +222,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 +277,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")))