free stack after cloned children finished

avoid children using the freed memory.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
This commit is contained in:
Gao feng
2016-02-26 13:56:14 +08:00
parent 4fc4ac0c46
commit d97485cfc0
2 changed files with 22 additions and 6 deletions
+8 -2
View File
@@ -6,6 +6,7 @@
#include <sys/stat.h>
#include <sys/epoll.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <sched.h>
#include <errno.h>
#include <string.h>
@@ -497,7 +498,7 @@ int hyper_exec_cmd(char *json, int length)
.exec = NULL,
.pipe = {-1, -1},
};
int pid, ret = -1;
int pid, ret = -1, status;
uint32_t type;
fprintf(stdout, "call hyper_exec_cmd, json %s, len %d\n", json, length);
@@ -532,13 +533,18 @@ int hyper_exec_cmd(char *json, int length)
goto close_tty;
}
pid = clone(hyper_do_exec_cmd, stack + stacksize, CLONE_VM| CLONE_FILES| SIGCHLD, &arg);
pid = clone(hyper_do_exec_cmd, stack + stacksize, CLONE_VM| CLONE_FILES| SIGQUIT, &arg);
fprintf(stdout, "do_exec_cmd pid %d\n", pid);
if (pid < 0) {
perror("clone hyper_do_exec_cmd failed");
goto close_tty;
}
if (waitpid(pid, &status, __WCLONE) <= 0) {
perror("waiting hyper_do_exec_cmd finish failed");
goto close_tty;
}
if (hyper_get_type(arg.pipe[0], &type) < 0 || type != READY) {
fprintf(stderr, "hyper init doesn't get execcmd ready message\n");
goto close_tty;
+14 -4
View File
@@ -426,7 +426,7 @@ int hyper_start_container_stage0(struct hyper_container *c, struct hyper_pod *po
.container = c,
.ctl_pipe = {-1, -1},
};
int ret = -1, pid;
int ret = -1, pid, status;
uint32_t type;
if (pipe2(arg.ctl_pipe, O_CLOEXEC) < 0) {
@@ -440,12 +440,17 @@ int hyper_start_container_stage0(struct hyper_container *c, struct hyper_pod *po
goto out;
}
pid = clone(hyper_container_stage0, stack + stacksize, CLONE_VM| CLONE_FILES| SIGCHLD, &arg);
pid = clone(hyper_container_stage0, stack + stacksize, CLONE_VM| CLONE_FILES| SIGQUIT, &arg);
if (pid < 0) {
perror("enter container pid ns failed");
goto out;
}
if (waitpid(pid, &status, __WCLONE) <= 0) {
perror("waiting hyper_container_stage0 finish failed");
goto out;
}
/* Wait for container start */
if (hyper_get_type(arg.ctl_pipe[0], &type) < 0) {
perror("get enter_container_pidns ready message failed");
@@ -931,7 +936,7 @@ static int hyper_cmd_read_file(char *json, int length, uint32_t *datalen, uint8_
};
int stacksize = getpagesize() * 4;
void *stack = NULL;
int pid, ret = -1;
int pid, ret = -1, status;
uint32_t type;
fprintf(stdout, "%s\n", __func__);
@@ -968,12 +973,17 @@ static int hyper_cmd_read_file(char *json, int length, uint32_t *datalen, uint8_
goto out;
}
pid = clone(hyper_do_cmd_read_file, stack + stacksize, CLONE_VM| SIGCHLD, &arg);
pid = clone(hyper_do_cmd_read_file, stack + stacksize, CLONE_VM| SIGQUIT, &arg);
if (pid < 0) {
perror("fail to fork writter process");
goto out;
}
if (waitpid(pid, &status, __WCLONE) <= 0) {
perror("waiting hyper_do_cmd_read_file finish failed");
goto out;
}
if (hyper_get_type(arg.pipe[0], &type) < 0 || type != READY) {
fprintf(stderr, "%s to incorrect type %" PRIu32 "\n", __func__, type);
goto out;