]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxclock: fall back to /tmp if xdg_rundir is not writeable
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 7 Jan 2014 05:39:02 +0000 (23:39 -0600)
committerStéphane Graber <stgraber@ubuntu.com>
Tue, 7 Jan 2014 14:22:52 +0000 (09:22 -0500)
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>
src/lxc/lxclock.c

index 3e1b054e594a15db409005d11b9f3b8c564304af..0ff71edda7f5f149fed29966948d4549968f2279 100644 (file)
@@ -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;