]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
fix failed to fallback at lxclock_name 408/head
authorKohei YOSHIDA <kohei.yoshida@gehirn.co.jp>
Thu, 22 Jan 2015 06:16:39 +0000 (15:16 +0900)
committerKohei YOSHIDA <kohei.yoshida@gehirn.co.jp>
Thu, 22 Jan 2015 06:16:39 +0000 (15:16 +0900)
lxclock_name will fallback to /tmp/$(id -u)/lxc$lxcpath/.$lxcname when failed
to create directories into rundir. But, in currently, lxclock_name returns
untill preparing directories under the /tmp, so invoker will fail to get
the container lock.  This patch fixes fixes this.

Signed-off-by: Kohei YOSHIDA <kohei.yoshida@gehirn.co.jp>
src/lxc/lxclock.c

index ea9be3c54848d38368cdd2160409ca4e0a65690d..922822c75981e7b75f7ef12eb665563e7565f1c6 100644 (file)
@@ -128,8 +128,11 @@ static char *lxclock_name(const char *p, const char *n)
        }
        ret = mkdir_p(dest, 0755);
        if (ret < 0) {
-               /* fall back to "/tmp/" $(id -u) "/lxc/" $lxcpath / $lxcname + '\0' */
-               int l2 = 34 + strlen(n) + strlen(p);
+               /* fall back to "/tmp/" + $(id -u) + "/lxc" + $lxcpath + "/" + "." + $lxcname + '\0'
+                * * maximum length of $(id -u) is 10 calculated by (log (2 ** (sizeof(uid_t) * 8) - 1) / log 10 + 1)
+                * * lxcpath always starts with '/'
+                */
+               int l2 = 22 + strlen(n) + strlen(p);
                if (l2 > len) {
                        char *d;
                        d = realloc(dest, l2);
@@ -141,13 +144,19 @@ static char *lxclock_name(const char *p, const char *n)
                        len = l2;
                        dest = d;
                }
-               ret = snprintf(dest, len, "/tmp/%d/lxc/%s", geteuid(), p);
+               ret = snprintf(dest, len, "/tmp/%d/lxc%s", geteuid(), p);
                if (ret < 0 || ret >= len) {
                        free(dest);
                        free(rundir);
                        return NULL;
                }
-               ret = snprintf(dest, len, "/tmp/%d/lxc/%s/.%s", geteuid(), p, n);
+               ret = mkdir_p(dest, 0755);
+               if (ret < 0) {
+                       free(dest);
+                       free(rundir);
+                       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);