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>
/* 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)
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) {
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;
}