lxccontainer: non-functional changes

parent eb70aaf0
......@@ -1236,7 +1236,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_
pid = fork();
if (pid < 0) {
SYSERROR("failed to fork task for container creation template");
SYSERROR("Failed to fork task for container creation template");
return false;
}
......@@ -1249,19 +1249,19 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_
struct lxc_conf *conf = c->lxc_conf;
if (need_null_stdfds && null_stdfds() < 0) {
_exit(1);
_exit(EXIT_FAILURE);
}
bdev = storage_init(c->lxc_conf);
if (!bdev) {
ERROR("Error opening rootfs");
_exit(1);
_exit(EXIT_FAILURE);
}
if (geteuid() == 0) {
if (unshare(CLONE_NEWNS) < 0) {
ERROR("error unsharing mounts");
_exit(1);
_exit(EXIT_FAILURE);
}
if (detect_shared_rootfs()) {
if (mount(NULL, "/", NULL, MS_SLAVE|MS_REC, NULL)) {
......@@ -1330,33 +1330,33 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_
newargv = malloc(nargs * sizeof(*newargv));
if (!newargv)
_exit(1);
_exit(EXIT_FAILURE);
newargv[0] = lxcbasename(tpath);
len = strlen(c->config_path) + strlen(c->name) + strlen("--path=") + 2;
patharg = malloc(len);
if (!patharg)
_exit(1);
_exit(EXIT_FAILURE);
ret = snprintf(patharg, len, "--path=%s/%s", c->config_path, c->name);
if (ret < 0 || ret >= len)
_exit(1);
_exit(EXIT_FAILURE);
newargv[1] = patharg;
len = strlen("--name=") + strlen(c->name) + 1;
namearg = malloc(len);
if (!namearg)
_exit(1);
_exit(EXIT_FAILURE);
ret = snprintf(namearg, len, "--name=%s", c->name);
if (ret < 0 || ret >= len)
_exit(1);
_exit(EXIT_FAILURE);
newargv[2] = namearg;
len = strlen("--rootfs=") + 1 + strlen(bdev->dest);
rootfsarg = malloc(len);
if (!rootfsarg)
_exit(1);
_exit(EXIT_FAILURE);
ret = snprintf(rootfsarg, len, "--rootfs=%s", bdev->dest);
if (ret < 0 || ret >= len)
_exit(1);
_exit(EXIT_FAILURE);
newargv[3] = rootfsarg;
/* add passed-in args */
......@@ -1368,7 +1368,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_
nargs++;
newargv = realloc(newargv, nargs * sizeof(*newargv));
if (!newargv)
_exit(1);
_exit(EXIT_FAILURE);
newargv[nargs - 1] = NULL;
/*
......@@ -1388,7 +1388,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_
if (!n2) {
SYSERROR("out of memory");
_exit(1);
_exit(EXIT_FAILURE);
}
newargv[0] = tpath;
tpath = "lxc-usernsexec";
......@@ -1398,63 +1398,63 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_
n2args += 2;
n2 = realloc(n2, n2args * sizeof(char *));
if (!n2)
_exit(1);
_exit(EXIT_FAILURE);
n2[n2args-2] = "-m";
n2[n2args-1] = malloc(200);
if (!n2[n2args-1])
_exit(1);
_exit(EXIT_FAILURE);
ret = snprintf(n2[n2args-1], 200, "%c:%lu:%lu:%lu",
map->idtype == ID_TYPE_UID ? 'u' : 'g',
map->nsid, map->hostid, map->range);
if (ret < 0 || ret >= 200)
_exit(1);
_exit(EXIT_FAILURE);
}
int hostid_mapped = mapped_hostid(geteuid(), conf, ID_TYPE_UID);
int extraargs = hostid_mapped >= 0 ? 1 : 3;
n2 = realloc(n2, (nargs + n2args + extraargs) * sizeof(char *));
if (!n2)
_exit(1);
_exit(EXIT_FAILURE);
if (hostid_mapped < 0) {
hostid_mapped = find_unmapped_nsid(conf, ID_TYPE_UID);
n2[n2args++] = "-m";
if (hostid_mapped < 0) {
ERROR("Could not find free uid to map");
_exit(1);
_exit(EXIT_FAILURE);
}
n2[n2args++] = malloc(200);
if (!n2[n2args-1]) {
SYSERROR("out of memory");
_exit(1);
_exit(EXIT_FAILURE);
}
ret = snprintf(n2[n2args-1], 200, "u:%d:%d:1",
hostid_mapped, geteuid());
if (ret < 0 || ret >= 200) {
ERROR("string too long");
_exit(1);
_exit(EXIT_FAILURE);
}
}
int hostgid_mapped = mapped_hostid(getegid(), conf, ID_TYPE_GID);
extraargs = hostgid_mapped >= 0 ? 1 : 3;
n2 = realloc(n2, (nargs + n2args + extraargs) * sizeof(char *));
if (!n2)
_exit(1);
_exit(EXIT_FAILURE);
if (hostgid_mapped < 0) {
hostgid_mapped = find_unmapped_nsid(conf, ID_TYPE_GID);
n2[n2args++] = "-m";
if (hostgid_mapped < 0) {
ERROR("Could not find free uid to map");
_exit(1);
_exit(EXIT_FAILURE);
}
n2[n2args++] = malloc(200);
if (!n2[n2args-1]) {
SYSERROR("out of memory");
_exit(1);
_exit(EXIT_FAILURE);
}
ret = snprintf(n2[n2args-1], 200, "g:%d:%d:1",
hostgid_mapped, getegid());
if (ret < 0 || ret >= 200) {
ERROR("string too long");
_exit(1);
_exit(EXIT_FAILURE);
}
}
n2[n2args++] = "--";
......@@ -1468,7 +1468,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_
n2 = realloc(n2, n2args * sizeof(char *));
if (!n2) {
SYSERROR("out of memory");
_exit(1);
_exit(EXIT_FAILURE);
}
/* note n2[n2args-1] is NULL */
n2[n2args-5] = "--mapped-uid";
......@@ -1484,7 +1484,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_
/* execute */
execvp(tpath, newargv);
SYSERROR("Failed to execute template %s", tpath);
_exit(1);
_exit(EXIT_FAILURE);
}
if (wait_for_pid(pid) != 0) {
......
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