shutdown vm immediately if no container remained

Hyperstart may receive destroy-event after all of the
containers are exited, then hyper_destroy_pod will still
try to term all processes, but there are no container will
exit and trigger the sending out podfinished-event/ack-event
logic in hyper_release_exec.

Add exec to global list only after process is running,
And add remains after container is running.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
This commit is contained in:
Gao feng
2016-09-20 22:19:21 +08:00
parent 504218c41f
commit 519db047fb
2 changed files with 10 additions and 8 deletions
+6 -6
View File
@@ -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]);
+4 -2
View File
@@ -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;
}