[lxc-devel] [PATCH] lxclock: fall back to /tmp if xdg_rundir is not writeable
Stéphane Graber
stgraber at ubuntu.com
Tue Jan 7 14:20:59 UTC 2014
On Mon, Jan 06, 2014 at 11:39:02PM -0600, Serge Hallyn wrote:
> 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 at ubuntu.com>
Acked-by: Stéphane Graber <stgraber at ubuntu.com>
> ---
> src/lxc/lxclock.c | 24 ++++++++++++++++++++----
> 1 file changed, 20 insertions(+), 4 deletions(-)
>
> diff --git a/src/lxc/lxclock.c b/src/lxc/lxclock.c
> index 69d3d15..c6f2448 100644
> --- a/src/lxc/lxclock.c
> +++ b/src/lxc/lxclock.c
> @@ -123,11 +123,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;
> --
> 1.8.5.2
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20140107/3d0456d5/attachment.pgp>
More information about the lxc-devel
mailing list