]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Set a reasonable fallback for get_rundir
authorStéphane Graber <stgraber@ubuntu.com>
Tue, 18 Feb 2014 22:33:51 +0000 (17:33 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Tue, 18 Feb 2014 23:45:22 +0000 (18:45 -0500)
If get_rundir can't find XDG_RUNTIME_DIR in the environment, it'll
attempt to build a path using ~/.cache/lxc/run/. Should that fail
because of missing $HOME in the environment, it'll then return NULL an
all callers will fail in that case.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxclock.c
src/lxc/monitor.c
src/lxc/utils.c

index 4f433ca6a4dc4b0b581c16e614c70daaa686bd44..598d6c0d0c46626c55323931a1ab2e1136e4be61 100644 (file)
@@ -109,6 +109,8 @@ static char *lxclock_name(const char *p, const char *n)
        /* length of "/lock/lxc/" + $lxcpath + "/" + $lxcname + '\0' */
        len = strlen("/lock/lxc/") + strlen(n) + strlen(p) + 2;
        rundir = get_rundir();
+       if (!rundir)
+               return NULL;
        len += strlen(rundir);
 
        if ((dest = malloc(len)) == NULL)
index ef658f5c461ce2940199714852e669d6dcaf4d0f..704cc225f600cc0368d0bb56f27dbf41c6db4f1a 100644 (file)
@@ -57,6 +57,9 @@ int lxc_monitor_fifo_name(const char *lxcpath, char *fifo_path, size_t fifo_path
        const char *rundir;
 
        rundir = get_rundir();
+       if (!rundir)
+               return -1;
+
        if (do_mkdirp) {
                ret = snprintf(fifo_path, fifo_path_sz, "%s/lxc/%s", rundir, lxcpath);
                if (ret < 0 || ret >= fifo_path_sz) {
index 3dff104df5364416c476d3bb64cc47f604a5fcd3..1f868a4ce1460f056f69d19367182f7df64266e4 100644 (file)
@@ -378,11 +378,25 @@ out:
 
 const char *get_rundir()
 {
-       const char *rundir;
+       char *rundir;
+       const char *homedir;
 
-       rundir = getenv("XDG_RUNTIME_DIR");
-       if (geteuid() == 0 || rundir == NULL)
+       if (geteuid() == 0)
                rundir = RUNTIME_PATH;
+
+       rundir = getenv("XDG_RUNTIME_DIR");
+       if (!rundir) {
+               INFO("XDG_RUNTIME_DIR isn't set in the environment.");
+               homedir = getenv("HOME");
+               if (!homedir) {
+                       ERROR("HOME isn't set in the environment.");
+                       return NULL;
+               }
+
+               rundir = malloc(sizeof(char) * (17 + strlen(homedir)));
+               sprintf(rundir, "%s/.cache/lxc/run/", homedir);
+       }
+
        return rundir;
 }