[systemd-devel] [PATCH 5/7] Move generator directories to XDG_{RUNTIME, SESSION}_DIR

Hristo Venev hristo at venev.name
Sun Dec 1 11:25:56 PST 2013


More predictable names, easier to find if debugging, deleted on
session/user termination
---
 src/core/manager.c | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/src/core/manager.c b/src/core/manager.c
index ada62d0..617fc9f 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -2436,7 +2436,7 @@ void manager_check_finished(Manager *m) {
 }
 
 static int create_generator_dir(Manager *m, char **generator, const char *name) {
-        char *p;
+        char *p, *e;
         int r;
 
         assert(m);
@@ -2459,16 +2459,37 @@ static int create_generator_dir(Manager *m, char **generator, const char *name)
                         free(p);
                         return r;
                 }
-        } else {
-                p = strjoin("/tmp/systemd-", name, ".XXXXXX", NULL);
+        } else if (m->running_as == SYSTEMD_USER) {
+                e = secure_getenv("XDG_RUNTIME_DIR");
+                if (!e)
+                        return -ENOENT;
+
+                p = strjoin(e, "/systemd/", name, NULL);
                 if (!p)
                         return log_oom();
 
-                if (!mkdtemp(p)) {
-                        log_error("Failed to create generator directory %s: %m",
-                                  p);
+                r = mkdir_p_label(p, 0755);
+                if (r < 0) {
+                        log_error("Failed to create generator directory %s: %s",
+                                  p, strerror(-r));
                         free(p);
-                        return -errno;
+                        return r;
+                }
+        } else if (m->running_as == SYSTEMD_SESSION) {
+                e = secure_getenv("XDG_SESSION_DIR");
+                if (!e)
+                        return -ENOENT;
+
+                p = strjoin(e, "/systemd/", name, NULL);
+                if (!p)
+                        return log_oom();
+
+                r = mkdir_p_label(p, 0755);
+                if (r < 0) {
+                        log_error("Failed to create generator directory %s: %s",
+                                  p, strerror(-r));
+                        free(p);
+                        return r;
                 }
         }
 
-- 
1.8.4.4



More information about the systemd-devel mailing list