3030#include "container.h"
3131#include "syscall.h"
3232
33- struct hyper_pod global_pod = {
33+ static struct hyper_pod global_pod = {
3434 .containers = LIST_HEAD_INIT (global_pod .containers ),
3535 .exec_head = LIST_HEAD_INIT (global_pod .exec_head ),
3636};
@@ -62,20 +62,11 @@ static int hyper_set_win_size(struct hyper_pod *pod, char *json, int length)
6262 goto out ;
6363 }
6464
65- struct hyper_container * c = hyper_find_container (pod , container );
66- if (!c ) {
67- fprintf (stderr , "call hyper_set_win_size, can not find the container : %s\n" , container );
65+ exec = hyper_find_process (pod , container , process );
66+ if (!exec ) {
67+ fprintf (stderr , "call hyper_set_win_size, can not find the process : %s\n" , process );
6868 goto out ;
6969 }
70- if (strcmp (c -> exec .id , process ) == 0 ) {
71- exec = & c -> exec ;
72- } else {
73- exec = hyper_find_exec_by_name (pod , process );
74- if (!exec ) {
75- fprintf (stderr , "call hyper_set_win_size, can not find the process: %s\n" , process );
76- goto out ;
77- }
78- }
7970
8071 size .ws_row = (int )json_object_get_number (json_object (value ), "row" );
8172 size .ws_col = (int )json_object_get_number (json_object (value ), "column" );
@@ -564,10 +555,8 @@ static int hyper_destroy_pod(struct hyper_pod *pod, int error)
564555 return 0 ;
565556}
566557
567- static int hyper_start_pod (char * json , int length )
558+ static int hyper_start_pod (struct hyper_pod * pod , char * json , int length )
568559{
569- struct hyper_pod * pod = & global_pod ;
570-
571560 fprintf (stdout , "call hyper_start_pod, json %s, len %d\n" , json , length );
572561
573562 if (pod -> init_pid )
@@ -593,11 +582,10 @@ static int hyper_start_pod(char *json, int length)
593582 return 0 ;
594583}
595584
596- static int hyper_new_container (char * json , int length )
585+ static int hyper_new_container (struct hyper_pod * pod , char * json , int length )
597586{
598587 int ret ;
599588 struct hyper_container * c ;
600- struct hyper_pod * pod = & global_pod ;
601589
602590 fprintf (stdout , "call hyper_new_container, json %s, len %d\n" , json , length );
603591
@@ -612,6 +600,12 @@ static int hyper_new_container(char *json, int length)
612600 return -1 ;
613601 }
614602
603+ if (hyper_find_container (pod , c -> id ) != NULL ) {
604+ fprintf (stderr , "container id conflicts" );
605+ hyper_cleanup_container (c , pod );
606+ return -1 ;
607+ }
608+
615609 list_add_tail (& c -> list , & pod -> containers );
616610 ret = hyper_setup_container (c , pod );
617611 if (ret >= 0 )
@@ -627,10 +621,9 @@ static int hyper_new_container(char *json, int length)
627621 return ret ;
628622}
629623
630- static int hyper_kill_container (char * json , int length )
624+ static int hyper_kill_container (struct hyper_pod * pod , char * json , int length )
631625{
632626 struct hyper_container * c ;
633- struct hyper_pod * pod = & global_pod ;
634627 int ret = -1 ;
635628
636629 JSON_Value * value = hyper_json_parse (json , length );
@@ -652,10 +645,9 @@ static int hyper_kill_container(char *json, int length)
652645 return ret ;
653646}
654647
655- static int hyper_remove_container (char * json , int length )
648+ static int hyper_remove_container (struct hyper_pod * pod , char * json , int length )
656649{
657650 struct hyper_container * c ;
658- struct hyper_pod * pod = & global_pod ;
659651 int ret = -1 ;
660652
661653 JSON_Value * value = hyper_json_parse (json , length );
@@ -719,7 +711,7 @@ static int hyper_open_container_file(void *data)
719711 exit (ret );
720712}
721713
722- static int hyper_cmd_rw_file (char * json , int length , uint32_t * rdatalen , uint8_t * * rdata , int rw )
714+ static int hyper_cmd_rw_file (struct hyper_pod * pod , char * json , int length , uint32_t * rdatalen , uint8_t * * rdata , int rw )
723715{
724716 struct file_command cmd = {
725717 .id = NULL ,
@@ -730,7 +722,6 @@ static int hyper_cmd_rw_file(char *json, int length, uint32_t *rdatalen, uint8_t
730722 .rw = rw ,
731723 };
732724 struct hyper_container * c ;
733- struct hyper_pod * pod = & global_pod ;
734725 char * data = NULL ;
735726 void * stack = NULL ;
736727 int stacksize = getpagesize () * 4 ;
@@ -1103,7 +1094,7 @@ static int hyper_ctlmsg_handle(struct hyper_event *he, uint32_t len)
11031094 hyper_set_be32 (data , APIVERSION );
11041095 break ;
11051096 case STARTPOD :
1106- ret = hyper_start_pod ((char * )buf -> data + 8 , len - 8 );
1097+ ret = hyper_start_pod (pod , (char * )buf -> data + 8 , len - 8 );
11071098 hyper_print_uptime ();
11081099 break ;
11091100 case DESTROYPOD :
@@ -1112,13 +1103,13 @@ static int hyper_ctlmsg_handle(struct hyper_event *he, uint32_t len)
11121103 hyper_destroy_pod (pod , 0 );
11131104 return 0 ;
11141105 case EXECCMD :
1115- ret = hyper_exec_cmd ((char * )buf -> data + 8 , len - 8 );
1106+ ret = hyper_exec_cmd (pod , (char * )buf -> data + 8 , len - 8 );
11161107 break ;
11171108 case WRITEFILE :
1118- ret = hyper_cmd_rw_file ((char * )buf -> data + 8 , len - 8 , NULL , NULL , WRITEFILE );
1109+ ret = hyper_cmd_rw_file (pod , (char * )buf -> data + 8 , len - 8 , NULL , NULL , WRITEFILE );
11191110 break ;
11201111 case READFILE :
1121- ret = hyper_cmd_rw_file ((char * )buf -> data + 8 , len - 8 , & datalen , & data , READFILE );
1112+ ret = hyper_cmd_rw_file (pod , (char * )buf -> data + 8 , len - 8 , & datalen , & data , READFILE );
11221113 break ;
11231114 case PING :
11241115 break ;
@@ -1129,13 +1120,13 @@ static int hyper_ctlmsg_handle(struct hyper_event *he, uint32_t len)
11291120 ret = hyper_set_win_size (pod , (char * )buf -> data + 8 , len - 8 );
11301121 break ;
11311122 case NEWCONTAINER :
1132- ret = hyper_new_container ((char * )buf -> data + 8 , len - 8 );
1123+ ret = hyper_new_container (pod , (char * )buf -> data + 8 , len - 8 );
11331124 break ;
11341125 case KILLCONTAINER :
1135- ret = hyper_kill_container ((char * )buf -> data + 8 , len - 8 );
1126+ ret = hyper_kill_container (pod , (char * )buf -> data + 8 , len - 8 );
11361127 break ;
11371128 case REMOVECONTAINER :
1138- ret = hyper_remove_container ((char * )buf -> data + 8 , len - 8 );
1129+ ret = hyper_remove_container (pod , (char * )buf -> data + 8 , len - 8 );
11391130 break ;
11401131 case ONLINECPUMEM :
11411132 hyper_cmd_online_cpu_mem ();
0 commit comments