Commit 97a696c6 by Stéphane Graber

Set a reasonable fallback for get_rundir

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: 's avatarStéphane Graber <stgraber@ubuntu.com> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent 8525b5e5
......@@ -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)
......
......@@ -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) {
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment