Commit 669b6325 by Kohei YOSHIDA

fix failed to fallback at lxclock_name

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: 's avatarKohei YOSHIDA <kohei.yoshida@gehirn.co.jp>
parent 3e73d667
......@@ -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);
......
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