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

Lennart Poettering lennart at poettering.net
Wed Apr 23 11:54:00 PDT 2014


On Fri, 28.03.14 19:38, Hristo Venev (hristo at venev.name) wrote:

> Predictable names and more consistent.

This definitely feels like the right thing to do.

> ---
>  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;
> -                }

Hmm, we still need the mkdtemp() here for the --system --test case, no?
Or am I missing something?

> +        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;

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list