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

Commit

Permalink
Merge pull request #361 from gnawux/kill_ret_master
Browse files Browse the repository at this point in the history
check the result of killing a container
  • Loading branch information
bergwolf committed Aug 2, 2018
2 parents 6fef3e0 + 96eba45 commit f2af9a5
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,12 @@ static int hyper_new_container(struct hyper_pod *pod, char *json, int length)
return ret;
}

static int hyper_kill_container(struct hyper_pod *pod, char *json, int length)
static int hyper_kill_container(struct hyper_pod *pod, char *json, int length, uint8_t **rmsg)
{
struct hyper_container *c;
int ret = -1;
size_t message_len = 0;
const char *emsg = NULL;

JSON_Value *value = hyper_json_parse(json, length);
if (value == NULL) {
Expand All @@ -654,13 +656,36 @@ static int hyper_kill_container(struct hyper_pod *pod, char *json, int length)
c = hyper_find_container(pod, id);
if (c == NULL) {
fprintf(stderr, "can not find container whose id is %s\n", id);
emsg = "no such container";
goto out;
}

kill(c->exec.pid, (int)json_object_get_number(json_object(value), "signal"));
ret = 0;
ret = kill(c->exec.pid, (int)json_object_get_number(json_object(value), "signal"));
if (ret <0) {
switch(errno) {
case EINVAL:
emsg = "invalid signal";
break;
case EPERM:
emsg = "no permission";
break;
case ESRCH:
emsg = "no such process";
break;
default:
emsg = "kill failed";
break;
}
}
out:
json_value_free(value);
if (emsg != NULL) {
message_len = strlen(emsg) + 1;
*rmsg = (uint8_t*)malloc(message_len);
if (*rmsg != NULL) {
strncpy((char*)*rmsg, emsg, message_len);
}
}
return ret;
}

Expand Down Expand Up @@ -1209,7 +1234,10 @@ static int hyper_ctlmsg_handle(struct hyper_event *he, uint32_t len)
ret = hyper_new_container(pod, (char *)buf->data + 8, len - 8);
break;
case KILLCONTAINER:
ret = hyper_kill_container(pod, (char *)buf->data + 8, len - 8);
ret = hyper_kill_container(pod, (char *)buf->data + 8, len - 8, &data);
if (data != NULL) {
datalen = strlen((char*)data) + 1;
}
break;
case REMOVECONTAINER:
ret = hyper_remove_container(pod, (char *)buf->data + 8, len - 8);
Expand Down

0 comments on commit f2af9a5

Please sign in to comment.