From f3f78303b15bec6c81a12d2e2e7021200688e66b Mon Sep 17 00:00:00 2001 From: Gao feng Date: Sat, 10 Oct 2015 20:49:20 +0800 Subject: [PATCH] cleanup pod after nobody use pod data Signed-off-by: Gao feng --- src/exec.c | 3 ++- src/hyper.h | 1 + src/init.c | 26 +++++++++++++++++--------- src/net.c | 11 ++++++++++- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/exec.c b/src/exec.c index c48e1df..64e42a7 100644 --- a/src/exec.c +++ b/src/exec.c @@ -524,6 +524,7 @@ int hyper_release_exec(struct hyper_exec *exec, /* stop pod, should not restart container */ if (pod->type == STOPPOD) { hyper_send_type(ctl.chan.fd, ACK); + hyper_cleanup_pod(pod); return 0; } @@ -531,7 +532,7 @@ int hyper_release_exec(struct hyper_exec *exec, if (pod->policy == POLICY_NEVER || ((pod->policy == POLICY_ONFAILURE) && pod->code == 0)) { hyper_send_finish(pod); - //hyper_shutdown(pod); + hyper_cleanup_pod(pod); return 0; } diff --git a/src/hyper.h b/src/hyper.h index 3dd7301..215eb72 100644 --- a/src/hyper.h +++ b/src/hyper.h @@ -88,6 +88,7 @@ int hyper_mkdir(char *hyper_path); int hyper_open_serial(char *tty); struct hyper_container *hyper_find_container(struct hyper_pod *pod, char *id); int hyper_start_containers(struct hyper_pod *pod); +void hyper_cleanup_pod(struct hyper_pod *pod); extern struct hyper_pod global_pod; extern struct hyper_ctl ctl; diff --git a/src/init.c b/src/init.c index e65a4ab..8af778b 100644 --- a/src/init.c +++ b/src/init.c @@ -911,6 +911,12 @@ out: return ret; } +static void hyper_cleanup_hostname(struct hyper_pod *pod) +{ + free(pod->hostname); + pod->hostname = NULL; +} + static void hyper_cleanup_shared(struct hyper_pod *pod) { if (pod->tag == NULL) { @@ -919,6 +925,7 @@ static void hyper_cleanup_shared(struct hyper_pod *pod) } free(pod->tag); + pod->tag = NULL; if (umount("/tmp/hyper/shared") < 0 && umount2("/tmp/hyper/shared", MNT_DETACH)) { perror("fail to umount 9p dir"); @@ -931,6 +938,16 @@ static void hyper_cleanup_shared(struct hyper_pod *pod) sync(); } +void hyper_cleanup_pod(struct hyper_pod *pod) +{ + hyper_cleanup_exec(pod); + hyper_cleanup_container(pod); + hyper_cleanup_network(pod); + hyper_cleanup_shared(pod); + hyper_cleanup_dns(pod); + hyper_cleanup_hostname(pod); +} + static int hyper_stop_pod(struct hyper_pod *pod) { fprintf(stdout, "hyper_stop_pod init_pid %d\n", pod->init_pid); @@ -940,16 +957,7 @@ static int hyper_stop_pod(struct hyper_pod *pod) } pod->init_pid = 0; - hyper_term_all(pod); - hyper_cleanup_exec(pod); - hyper_cleanup_container(pod); - hyper_cleanup_network(pod); - hyper_cleanup_dns(pod); - hyper_cleanup_shared(pod); - - free(pod->hostname); - return 0; } diff --git a/src/net.c b/src/net.c index 378f59e..bd4a58a 100644 --- a/src/net.c +++ b/src/net.c @@ -869,8 +869,17 @@ out: void hyper_cleanup_dns(struct hyper_pod *pod) { - int fd = open("/tmp/hyper/resolv.conf", O_WRONLY| O_TRUNC); + int fd, i; + for (i = 0; i < pod->d_num; i++) { + free(pod->dns[i]); + } + + free(pod->dns); + pod->dns = NULL; + pod->d_num = 0; + + fd = open("/tmp/hyper/resolv.conf", O_WRONLY| O_TRUNC); if (fd < 0) { perror("open /tmp/hyper/resolv.conf failed"); return;