mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-14 03:31:36 +00:00
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: Serge Hallyn <serge.hallyn@ubuntu.com> Acked-by: Stéphane Graber <stgraber@ubuntu.com>
This commit is contained in:
parent
38d626f8be
commit
8c9c2c6d74
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user