Commit 8c9c2c6d by Serge Hallyn Committed by Stéphane Graber

lxclock: fall back to /tmp if xdg_rundir is not writeable

This happens for instance if you run a test under sudo which then runs lxc commands under 'su - <someuser>' Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 38d626f8
......@@ -121,11 +121,27 @@ static char *lxclock_name(const char *p, const char *n)
}
ret = mkdir_p(dest, 0755);
if (ret < 0) {
free(dest);
return NULL;
}
/* fall back to "/tmp/" $(id -u) "/lxc/" $lxcpath / $lxcname + '\0' */
int l2 = 33 + strlen(n) + strlen(p);
char *d;
if (l2 > len) {
d = realloc(dest, l2);
if (!d) {
free(dest);
return NULL;
}
len = l2;
}
dest = d;
ret = snprintf(dest, len, "/tmp/%d/lxc/%s", geteuid(), p);
if (ret < 0 || ret >= len) {
free(dest);
return NULL;
}
ret = snprintf(dest, len, "/tmp/%d/lxc/%s/%s", geteuid(), p, n);
} else
ret = snprintf(dest, len, "%s/lock/lxc/%s/%s", rundir, p, n);
ret = snprintf(dest, len, "%s/lock/lxc/%s/%s", rundir, p, n);
if (ret < 0 || ret >= len) {
free(dest);
return NULL;
......
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