chiark / gitweb /
mount: require fsck
[elogind.git] / src / path-lookup.c
index 1c4b5dc4e1f6bc1c37eb3261432a67db6fa4e4fe..c746e5e1ad5895076921a396b836fbc4e4c8cc0a 100644 (file)
@@ -1,4 +1,4 @@
-/*-*- Mode: C; c-basic-offset: 8 -*-*/
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
 
 /***
   This file is part of systemd.
 
 #include "path-lookup.h"
 
+int session_config_home(char **config_home) {
+        const char *e;
+
+        if ((e = getenv("XDG_CONFIG_HOME"))) {
+                if (asprintf(config_home, "%s/systemd/session", e) < 0)
+                        return -ENOMEM;
+
+                return 1;
+        } else {
+                const char *home;
+
+                if ((home = getenv("HOME"))) {
+                        if (asprintf(config_home, "%s/.config/systemd/session", home) < 0)
+                                return -ENOMEM;
+
+                        return 1;
+                }
+        }
+
+        return 0;
+}
+
 static char** session_dirs(void) {
         const char *home, *e;
         char *config_home = NULL, *data_home = NULL;
@@ -45,16 +67,10 @@ static char** session_dirs(void) {
          * as data, and allow overriding as configuration.
          */
 
-        home = getenv("HOME");
-
-        if ((e = getenv("XDG_CONFIG_HOME"))) {
-                if (asprintf(&config_home, "%s/systemd/session", e) < 0)
-                        goto fail;
+        if (session_config_home(&config_home) < 0)
+                goto fail;
 
-        } else if (home) {
-                if (asprintf(&config_home, "%s/.config/systemd/session", home) < 0)
-                        goto fail;
-        }
+        home = getenv("HOME");
 
         if ((e = getenv("XDG_CONFIG_DIRS")))
                 if (!(config_dirs = strv_split(e, ":")))
@@ -80,7 +96,7 @@ static char** session_dirs(void) {
                  * one. */
 
                 mkdir_parents(data_home, 0777);
-                symlink("../../../.config/systemd/session", data_home);
+                (void) symlink("../../../.config/systemd/session", data_home);
         }
 
         if ((e = getenv("XDG_DATA_DIRS")))
@@ -165,13 +181,37 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as) {
                                 return -ENOMEM;
                 } else
                         if (!(p->unit_path = strv_new(
-                                              SYSTEM_CONFIG_UNIT_PATH,  /* /etc/systemd/system/ */
-                                              SYSTEM_DATA_UNIT_PATH,    /* /lib/systemd/system/ */
+                                              "/dev/.systemd/system",
+                                              SYSTEM_CONFIG_UNIT_PATH,
+                                              "/etc/systemd/system",
+                                              "/usr/local/share/systemd/system",
+                                              "/usr/share/systemd/system",
+                                              "/lib/systemd/system",
+                                              SYSTEM_DATA_UNIT_PATH,
                                               NULL)))
                                 return -ENOMEM;
         }
 
-        if (running_as == MANAGER_INIT) {
+        if (p->unit_path)
+                if (!strv_path_canonicalize(p->unit_path))
+                        return -ENOMEM;
+
+        strv_uniq(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
                 /* /etc/init.d/ compatibility does not matter to users */
 
                 if ((e = getenv("SYSTEMD_SYSVINIT_PATH")))
@@ -199,60 +239,46 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as) {
                                               NULL)))
                                 return -ENOMEM;
                 }
-        }
-
-        if (p->unit_path)
-                if (!strv_path_canonicalize(p->unit_path))
-                        return -ENOMEM;
 
-        if (p->sysvinit_path)
-                if (!strv_path_canonicalize(p->sysvinit_path))
-                        return -ENOMEM;
+                if (p->sysvinit_path)
+                        if (!strv_path_canonicalize(p->sysvinit_path))
+                                return -ENOMEM;
 
-        if (p->sysvrcnd_path)
-                if (!strv_path_canonicalize(p->sysvrcnd_path))
-                        return -ENOMEM;
+                if (p->sysvrcnd_path)
+                        if (!strv_path_canonicalize(p->sysvrcnd_path))
+                                return -ENOMEM;
 
-        strv_uniq(p->unit_path);
-        strv_uniq(p->sysvinit_path);
-        strv_uniq(p->sysvrcnd_path);
+                strv_uniq(p->sysvinit_path);
+                strv_uniq(p->sysvrcnd_path);
 
-        if (!strv_isempty(p->unit_path)) {
+                if (!strv_isempty(p->sysvinit_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 (!strv_isempty(p->sysvinit_path)) {
-
-                if (!(t = strv_join(p->sysvinit_path, "\n\t")))
-                        return -ENOMEM;
+                        if (!(t = strv_join(p->sysvinit_path, "\n\t")))
+                                return -ENOMEM;
 
-                log_debug("Looking for SysV init scripts in:\n\t%s", t);
-                free(t);
-        } else {
-                log_debug("Ignoring SysV init scripts.");
-                strv_free(p->sysvinit_path);
-                p->sysvinit_path = NULL;
-        }
+                        log_debug("Looking for SysV init scripts in:\n\t%s", t);
+                        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 (!strv_isempty(p->sysvrcnd_path)) {
 
-                if (!(t = strv_join(p->sysvrcnd_path, "\n\t")))
-                        return -ENOMEM;
+                        if (!(t = strv_join(p->sysvrcnd_path, "\n\t")))
+                                return -ENOMEM;
 
-                log_debug("Looking for SysV rcN.d links in:\n\t%s", t);
-                free(t);
-        } else {
-                log_debug("Ignoring SysV rcN.d links.");
-                strv_free(p->sysvrcnd_path);
-                p->sysvrcnd_path = NULL;
+                        log_debug("Looking for SysV rcN.d links in:\n\t%s", t);
+                        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;
@@ -262,8 +288,11 @@ void lookup_paths_free(LookupPaths *p) {
         assert(p);
 
         strv_free(p->unit_path);
+        p->unit_path = NULL;
+
+#ifdef HAVE_SYSV_COMPAT
         strv_free(p->sysvinit_path);
         strv_free(p->sysvrcnd_path);
-
-        p->unit_path = p->sysvinit_path = p->sysvrcnd_path = NULL;
+        p->sysvinit_path = p->sysvrcnd_path = NULL;
+#endif
 }