chiark / gitweb /
journald: allow restarting journald without losing stream connections
[elogind.git] / src / shared / path-lookup.c
index 7a715b713375cb23aa8798762c266e535c6e1e49..051f1a4835c4ae99c90a0de6f34e62498f14306a 100644 (file)
@@ -61,6 +61,23 @@ int user_config_home(char **config_home) {
         return 0;
 }
 
+int user_runtime_dir(char **runtime_dir) {
+        const char *e;
+        char *r;
+
+        e = getenv("XDG_RUNTIME_DIR");
+        if (e) {
+                r = strappend(e, "/systemd/user");
+                if (!r)
+                        return -ENOMEM;
+
+                *runtime_dir = r;
+                return 1;
+        }
+
+        return 0;
+}
+
 static char** user_dirs(
                 const char *generator,
                 const char *generator_early,
@@ -69,10 +86,11 @@ static char** user_dirs(
         const char * const config_unit_paths[] = {
                 USER_CONFIG_UNIT_PATH,
                 "/etc/systemd/user",
-                "/run/systemd/user",
                 NULL
         };
 
+        const char * const runtime_unit_path = "/run/systemd/user";
+
         const char * const data_unit_paths[] = {
                 "/usr/local/lib/systemd/user",
                 "/usr/local/share/systemd/user",
@@ -83,7 +101,7 @@ static char** user_dirs(
         };
 
         const char *home, *e;
-        _cleanup_free_ char *config_home = NULL, *data_home = NULL;
+        _cleanup_free_ char *config_home = NULL, *runtime_dir = NULL, *data_home = NULL;
         _cleanup_strv_free_ char **config_dirs = NULL, **data_dirs = NULL;
         char **r = NULL;
 
@@ -99,6 +117,9 @@ static char** user_dirs(
         if (user_config_home(&config_home) < 0)
                 goto fail;
 
+        if (user_runtime_dir(&runtime_dir) < 0)
+                goto fail;
+
         home = getenv("HOME");
 
         e = getenv("XDG_CONFIG_DIRS");
@@ -148,6 +169,13 @@ static char** user_dirs(
         if (strv_extend_strv(&r, (char**) config_unit_paths) < 0)
                 goto fail;
 
+        if (runtime_dir)
+                if (strv_extend(&r, runtime_dir) < 0)
+                        goto fail;
+
+        if (strv_extend(&r, runtime_unit_path) < 0)
+                goto fail;
+
         if (generator)
                 if (strv_extend(&r, generator) < 0)
                         goto fail;
@@ -212,7 +240,7 @@ int lookup_paths_init(
         if (!p->unit_path || append) {
                 /* Let's figure something out. */
 
-                char **unit_path;
+                _cleanup_strv_free_ char **unit_path;
                 int r;
 
                 /* For the user units we include share/ in the search
@@ -370,3 +398,19 @@ void lookup_paths_free(LookupPaths *p) {
         p->sysvinit_path = p->sysvrcnd_path = NULL;
 #endif
 }
+
+int lookup_paths_init_from_scope(LookupPaths *paths,
+                                 UnitFileScope scope,
+                                 const char *root_dir) {
+        assert(paths);
+        assert(scope >= 0);
+        assert(scope < _UNIT_FILE_SCOPE_MAX);
+
+        zero(*paths);
+
+        return lookup_paths_init(paths,
+                                 scope == UNIT_FILE_SYSTEM ? SYSTEMD_SYSTEM : SYSTEMD_USER,
+                                 scope == UNIT_FILE_USER,
+                                 root_dir,
+                                 NULL, NULL, NULL);
+}