lxccontainer: non-functional changes

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