Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 3d53c5a

Browse files
committed
add argument struct hyper_pod *pod to functions
Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
1 parent 4f6aeb8 commit 3d53c5a

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

src/exec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ static void hyper_free_exec(struct hyper_exec *exec)
590590
free(exec);
591591
}
592592

593-
int hyper_exec_cmd(char *json, int length)
593+
int hyper_exec_cmd(struct hyper_pod *pod, char *json, int length)
594594
{
595595
struct hyper_exec *exec;
596596

@@ -602,7 +602,7 @@ int hyper_exec_cmd(char *json, int length)
602602
return -1;
603603
}
604604

605-
exec->pod = &global_pod;
605+
exec->pod = pod;
606606
int ret = hyper_run_process(exec);
607607
if (ret < 0) {
608608
hyper_free_exec(exec);

src/exec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct hyper_exec {
4444

4545
struct hyper_pod;
4646

47-
int hyper_exec_cmd(char *json, int length);
47+
int hyper_exec_cmd(struct hyper_pod *pod, char *json, int length);
4848
int hyper_run_process(struct hyper_exec *e);
4949
struct hyper_exec *hyper_find_process(struct hyper_pod *pod, const char *container, const char *process);
5050
struct hyper_exec *hyper_find_exec_by_name(struct hyper_pod *pod, const char *process);

src/hyper.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ int hyper_enter_sandbox(struct hyper_pod *pod, int pidpipe);
8787
void hyper_pod_destroyed(int failed);
8888
int hyper_ctl_append_msg(struct hyper_event *he, uint32_t type, uint8_t *data, uint32_t len);
8989

90-
extern struct hyper_pod global_pod;
9190
extern struct hyper_epoll hyper_epoll;
9291
extern sigset_t orig_mask;
9392
#endif

src/init.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
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
};
@@ -555,10 +555,8 @@ static int hyper_destroy_pod(struct hyper_pod *pod, int error)
555555
return 0;
556556
}
557557

558-
static int hyper_start_pod(char *json, int length)
558+
static int hyper_start_pod(struct hyper_pod *pod, char *json, int length)
559559
{
560-
struct hyper_pod *pod = &global_pod;
561-
562560
fprintf(stdout, "call hyper_start_pod, json %s, len %d\n", json, length);
563561

564562
if (pod->init_pid)
@@ -584,11 +582,10 @@ static int hyper_start_pod(char *json, int length)
584582
return 0;
585583
}
586584

587-
static int hyper_new_container(char *json, int length)
585+
static int hyper_new_container(struct hyper_pod *pod, char *json, int length)
588586
{
589587
int ret;
590588
struct hyper_container *c;
591-
struct hyper_pod *pod = &global_pod;
592589

593590
fprintf(stdout, "call hyper_new_container, json %s, len %d\n", json, length);
594591

@@ -624,10 +621,9 @@ static int hyper_new_container(char *json, int length)
624621
return ret;
625622
}
626623

627-
static int hyper_kill_container(char *json, int length)
624+
static int hyper_kill_container(struct hyper_pod *pod, char *json, int length)
628625
{
629626
struct hyper_container *c;
630-
struct hyper_pod *pod = &global_pod;
631627
int ret = -1;
632628

633629
JSON_Value *value = hyper_json_parse(json, length);
@@ -649,10 +645,9 @@ static int hyper_kill_container(char *json, int length)
649645
return ret;
650646
}
651647

652-
static int hyper_remove_container(char *json, int length)
648+
static int hyper_remove_container(struct hyper_pod *pod, char *json, int length)
653649
{
654650
struct hyper_container *c;
655-
struct hyper_pod *pod = &global_pod;
656651
int ret = -1;
657652

658653
JSON_Value *value = hyper_json_parse(json, length);
@@ -716,7 +711,7 @@ static int hyper_open_container_file(void *data)
716711
exit(ret);
717712
}
718713

719-
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)
720715
{
721716
struct file_command cmd = {
722717
.id = NULL,
@@ -727,7 +722,6 @@ static int hyper_cmd_rw_file(char *json, int length, uint32_t *rdatalen, uint8_t
727722
.rw = rw,
728723
};
729724
struct hyper_container *c;
730-
struct hyper_pod *pod = &global_pod;
731725
char *data = NULL;
732726
void *stack = NULL;
733727
int stacksize = getpagesize() * 4;
@@ -1102,7 +1096,7 @@ static int hyper_ctlmsg_handle(struct hyper_event *he, uint32_t len)
11021096
hyper_set_be32(data, APIVERSION);
11031097
break;
11041098
case STARTPOD:
1105-
ret = hyper_start_pod((char *)buf->data + 8, len - 8);
1099+
ret = hyper_start_pod(pod, (char *)buf->data + 8, len - 8);
11061100
hyper_print_uptime();
11071101
break;
11081102
case DESTROYPOD:
@@ -1111,13 +1105,13 @@ static int hyper_ctlmsg_handle(struct hyper_event *he, uint32_t len)
11111105
hyper_destroy_pod(pod, 0);
11121106
return 0;
11131107
case EXECCMD:
1114-
ret = hyper_exec_cmd((char *)buf->data + 8, len - 8);
1108+
ret = hyper_exec_cmd(pod, (char *)buf->data + 8, len - 8);
11151109
break;
11161110
case WRITEFILE:
1117-
ret = hyper_cmd_rw_file((char *)buf->data + 8, len - 8, NULL, NULL, WRITEFILE);
1111+
ret = hyper_cmd_rw_file(pod, (char *)buf->data + 8, len - 8, NULL, NULL, WRITEFILE);
11181112
break;
11191113
case READFILE:
1120-
ret = hyper_cmd_rw_file((char *)buf->data + 8, len - 8, &datalen, &data, READFILE);
1114+
ret = hyper_cmd_rw_file(pod, (char *)buf->data + 8, len - 8, &datalen, &data, READFILE);
11211115
break;
11221116
case PING:
11231117
break;
@@ -1128,13 +1122,13 @@ static int hyper_ctlmsg_handle(struct hyper_event *he, uint32_t len)
11281122
ret = hyper_set_win_size(pod, (char *)buf->data + 8, len - 8);
11291123
break;
11301124
case NEWCONTAINER:
1131-
ret = hyper_new_container((char *)buf->data + 8, len - 8);
1125+
ret = hyper_new_container(pod, (char *)buf->data + 8, len - 8);
11321126
break;
11331127
case KILLCONTAINER:
1134-
ret = hyper_kill_container((char *)buf->data + 8, len - 8);
1128+
ret = hyper_kill_container(pod, (char *)buf->data + 8, len - 8);
11351129
break;
11361130
case REMOVECONTAINER:
1137-
ret = hyper_remove_container((char *)buf->data + 8, len - 8);
1131+
ret = hyper_remove_container(pod, (char *)buf->data + 8, len - 8);
11381132
break;
11391133
case ONLINECPUMEM:
11401134
hyper_cmd_online_cpu_mem();

0 commit comments

Comments
 (0)