diff --git a/src/exec.c b/src/exec.c index 14d51e1..b1f078f 100644 --- a/src/exec.c +++ b/src/exec.c @@ -545,13 +545,7 @@ int hyper_release_exec(struct hyper_exec *exec, fprintf(stdout, "%s container init exited, type %d, remains %d, policy %d\n", __func__, pod->type, pod->remains, pod->policy); - if (exec->init == 2) { // dynamic container - struct hyper_container *c = container_of(exec, struct hyper_container, exec); - // TODO send finish of this container and full cleanup - hyper_cleanup_container(c); - return 0; - } - + // TODO send finish of this container and full cleanup if (--pod->remains > 0) return 0; diff --git a/src/hyper.h b/src/hyper.h index 8142c48..083867f 100644 --- a/src/hyper.h +++ b/src/hyper.h @@ -51,6 +51,7 @@ struct hyper_pod { uint32_t e_num; uint32_t d_num; uint32_t type; + /* how many containers are running */ uint32_t remains; uint8_t policy; int efd; diff --git a/src/init.c b/src/init.c index 2cb20b8..fe431b3 100644 --- a/src/init.c +++ b/src/init.c @@ -457,6 +457,8 @@ int hyper_start_container_stage0(struct hyper_container *c, struct hyper_pod *po goto out; } + /* container process is spawned and ready to execute */ + pod->remains++; ret = 0; out: close(arg.ctl_pipe[0]); @@ -696,8 +698,10 @@ static int hyper_new_container(char *json, int length) fprintf(stdout, "call hyper_new_container, json %s, len %d\n", json, length); - if (!pod->init_pid) + if (!pod->init_pid) { fprintf(stdout, "the pod is not created yet\n"); + return -1; + } c = hyper_parse_new_container(pod, json, length); if (c == NULL) { @@ -705,15 +709,14 @@ static int hyper_new_container(char *json, int length) return -1; } + list_add_tail(&c->list, &pod->containers); ret = hyper_start_container_stage0(c, pod); if (ret < 0) { //TODO full grace cleanup hyper_cleanup_container(c); - return ret; } - list_add_tail(&c->list, &pod->containers); - return 0; + return ret; } static int hyper_cmd_write_file(char *json, int length) @@ -1114,7 +1117,7 @@ static int hyper_channel_handle(struct hyper_event *de, uint32_t len) hyper_print_uptime(); break; case STOPPOD: - ret = hyper_stop_pod(pod); + hyper_stop_pod(pod); return 0; //break; case DESTROYPOD: diff --git a/src/parse.c b/src/parse.c index 3cf7869..bdddbda 100644 --- a/src/parse.c +++ b/src/parse.c @@ -469,7 +469,6 @@ static int hyper_parse_containers(struct hyper_pod *pod, char *json, jsmntok_t * i += next; } - pod->remains = c_num; return i; fail: list_for_each_entry_safe(c, n, &pod->containers, list) @@ -733,7 +732,6 @@ realloc: if (hyper_parse_container(pod, &c, json, toks) < 0) goto fail; - c->exec.init = 2; // dynamic container type free(toks); return c;