diff --git a/src/exec.c b/src/exec.c index ace5ba0..cf23c44 100644 --- a/src/exec.c +++ b/src/exec.c @@ -634,7 +634,6 @@ int hyper_run_process(struct hyper_exec *exec) goto close_tty; } - list_add_tail(&exec->list, &pod->exec_head); exec->ref++; if (pipe2(pipe, O_CLOEXEC) < 0) { @@ -644,20 +643,21 @@ int hyper_run_process(struct hyper_exec *exec) pid = fork(); if (pid < 0) { - perror("clone hyper_do_exec_cmd failed"); + perror("fork prerequisite process failed"); goto close_tty; } else if (pid == 0) { hyper_do_exec_cmd(exec, pod, pipe[1]); } - fprintf(stdout, "do_exec_cmd pid %d\n", pid); + fprintf(stdout, "prerequisite process pid %d\n", pid); if (hyper_get_type(pipe[0], &type) < 0 || (int)type < 0) { - fprintf(stderr, "hyper init doesn't get execcmd ready message\n"); + fprintf(stderr, "run process failed\n"); goto close_tty; } - exec->pid = type; - fprintf(stdout, "%s get ready message %"PRIu32 "\n", __func__, type); + exec->pid = type; + list_add_tail(&exec->list, &pod->exec_head); + fprintf(stdout, "%s process pid %d\n", __func__, exec->pid); ret = 0; out: close(pipe[0]); diff --git a/src/init.c b/src/init.c index 0e34b88..2a01091 100644 --- a/src/init.c +++ b/src/init.c @@ -527,7 +527,7 @@ void hyper_pod_destroyed(int failed) static int hyper_destroy_pod(struct hyper_pod *pod, int error) { - if (pod->init_pid == 0) { + if (pod->init_pid == 0 || pod->remains == 0) { /* Pod stopped, just shutdown */ hyper_pod_destroyed(error); } else { @@ -589,11 +589,13 @@ static int hyper_new_container(char *json, int length) ret = hyper_setup_container(c, pod); if (ret >= 0) ret = hyper_run_process(&c->exec); + if (ret < 0) { //TODO full grace cleanup hyper_cleanup_container(c, pod); + } else { + pod->remains++; } - pod->remains++; return ret; }