From 20158b9033f10a9522e03136433608034145bedb Mon Sep 17 00:00:00 2001 From: YaoZengzeng <461941420@qq.com> Date: Wed, 22 Jun 2016 23:39:15 -0700 Subject: [PATCH] Support for removing container Signed-off-by: Yao Zengzeng --- src/hyper.h | 1 + src/init.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/hyper.h b/src/hyper.h index 5bce5f0..8fdca60 100644 --- a/src/hyper.h +++ b/src/hyper.h @@ -37,6 +37,7 @@ enum { ONLINECPUMEM, SETUPINTERFACE, SETUPROUTE, + REMOVECONTAINER, }; enum { diff --git a/src/init.c b/src/init.c index 6832b9b..b40e686 100644 --- a/src/init.c +++ b/src/init.c @@ -698,6 +698,37 @@ out: return ret; } +static int hyper_remove_container(char *json, int length) +{ + struct hyper_container *c; + struct hyper_pod *pod = &global_pod; + int ret = -1; + + JSON_Value *value = hyper_json_parse(json, length); + if (value == NULL) { + goto out; + } + + const char *id = json_object_get_string(json_object(value), "container"); + c = hyper_find_container(pod, id); + if (c == NULL) { + fprintf(stderr, "can not find container whose id is %s\n", id); + goto out; + } + + if (c->exec.exit != 1) { + fprintf(stderr, "container %s has not been stopped\n", id); + goto out; + } + + hyper_cleanup_container(c, pod); + + ret = 0; +out: + json_value_free(value); + return ret; +} + static int hyper_cmd_write_file(char *json, int length) { struct hyper_writter writter; @@ -1147,6 +1178,9 @@ static int hyper_channel_handle(struct hyper_event *de, uint32_t len) case KILLCONTAINER: ret = hyper_kill_container((char *)buf->data + 8, len - 8); break; + case REMOVECONTAINER: + ret = hyper_remove_container((char *)buf->data + 8, len - 8); + break; case ONLINECPUMEM: hyper_cmd_online_cpu_mem(); break;