[systemd-devel] [PATCH 1/3] core: Move user generator directories to XDG_RUNTIME_DIR

Hristo Venev hristo at venev.name
Fri Mar 28 10:38:50 PDT 2014


Predictable names and more consistent.
---
 src/core/manager.c | 48 +++++++++++-------------------------------------
 1 file changed, 11 insertions(+), 37 deletions(-)

diff --git a/src/core/manager.c b/src/core/manager.c
index ce8759e..b409738 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -2550,50 +2550,24 @@ static int create_generator_dir(Manager *m, char **generator, const char *name)
         if (*generator)
                 return 0;
 
-        if (m->running_as == SYSTEMD_SYSTEM && getpid() == 1) {
-                /* systemd --system, not running --test */
-
-                p = strappend("/run/systemd/", name);
-                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;
-                }
-        } else if (m->running_as == SYSTEMD_USER) {
-                const char *s = NULL;
+        if (m->running_as == SYSTEMD_SYSTEM && getpid() != 1) {
+                /* systemd --system --test */
 
-                s = getenv("XDG_RUNTIME_DIR");
-                if (!s)
-                        return -EINVAL;
-                p = strjoin(s, "/systemd/", name, NULL);
+                p = strjoin("/tmp/systemd-", name, ".XXXXXX", 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;
-                }
         } else {
-                /* systemd --system --test */
-
-                p = strjoin("/tmp/systemd-", name, ".XXXXXX", NULL);
+                p = strjoin(manager_get_runtime_prefix(m), "/systemd/", name, NULL);
                 if (!p)
                         return log_oom();
+        }
 
-                if (!mkdtemp(p)) {
-                        log_error("Failed to create generator directory %s: %m",
-                                  p);
-                        free(p);
-                        return -errno;
-                }
+        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;
         }
 
         *generator = p;
-- 
1.9.1



More information about the systemd-devel mailing list