|
29 | 29 | #include "container.h" |
30 | 30 |
|
31 | 31 | struct hyper_pod global_pod = { |
| 32 | + .dyn_containers = LIST_HEAD_INIT(global_pod.dyn_containers), |
32 | 33 | .exec_head = LIST_HEAD_INIT(global_pod.exec_head), |
33 | 34 | }; |
34 | 35 | struct hyper_exec *global_exec; |
@@ -690,26 +691,29 @@ static int hyper_start_pod(char *json, int length) |
690 | 691 | static int hyper_new_container(char *json, int length) |
691 | 692 | { |
692 | 693 | int ret; |
| 694 | + struct hyper_container *c; |
693 | 695 | struct hyper_pod *pod = &global_pod; |
694 | 696 |
|
695 | 697 | fprintf(stdout, "call hyper_new_container, json %s, len %d\n", json, length); |
696 | 698 |
|
697 | 699 | if (!pod->init_pid) |
698 | 700 | fprintf(stdout, "the pod is not created yet\n"); |
699 | 701 |
|
700 | | - if (hyper_parse_new_container(pod, json, length) < 0) { |
| 702 | + c = hyper_parse_new_container(pod, json, length); |
| 703 | + if (c == NULL) { |
701 | 704 | fprintf(stderr, "parse container json failed\n"); |
702 | 705 | return -1; |
703 | 706 | } |
704 | 707 |
|
705 | | - ret = hyper_start_container_stage0(&pod->c[pod->c_num - 1], pod); |
| 708 | + ret = hyper_start_container_stage0(c, pod); |
706 | 709 | if (ret < 0) { |
707 | 710 | //TODO full grace cleanup |
708 | | - pod->remains -= 1; |
709 | | - pod->c_num -= 1; |
| 711 | + hyper_cleanup_container(c); |
| 712 | + free(c); |
710 | 713 | return ret; |
711 | 714 | } |
712 | 715 |
|
| 716 | + list_add_tail(&c->dyn, &pod->dyn_containers); |
713 | 717 | return 0; |
714 | 718 | } |
715 | 719 |
|
@@ -977,7 +981,7 @@ static void hyper_cleanup_shared(struct hyper_pod *pod) |
977 | 981 |
|
978 | 982 | void hyper_cleanup_pod(struct hyper_pod *pod) |
979 | 983 | { |
980 | | - hyper_cleanup_container(pod); |
| 984 | + hyper_cleanup_containers(pod); |
981 | 985 | hyper_cleanup_network(pod); |
982 | 986 | hyper_cleanup_shared(pod); |
983 | 987 | hyper_cleanup_dns(pod); |
|
0 commit comments