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

Commit a7025da

Browse files
authored
Merge pull request #245 from laijs/signal-process
add SignalProcess command
2 parents 793064d + fecbb39 commit a7025da

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ enum {
3030
SETUPROUTE,
3131
REMOVECONTAINER,
3232
PROCESSASYNCEVENT,
33+
SIGNALPROCESS,
3334
};
3435

3536
/*

src/init.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,31 @@ static int hyper_kill_container(struct hyper_pod *pod, char *json, int length)
644644
return ret;
645645
}
646646

647+
static int hyper_signal_process(struct hyper_pod *pod, char *json, int length)
648+
{
649+
struct hyper_exec *exec;
650+
int ret = -1;
651+
652+
JSON_Value *value = hyper_json_parse(json, length);
653+
if (value == NULL) {
654+
goto out;
655+
}
656+
657+
const char *container = json_object_get_string(json_object(value), "container");
658+
const char *process = json_object_get_string(json_object(value), "process");
659+
exec = hyper_find_process(pod, container, process);
660+
if (exec == NULL) {
661+
fprintf(stderr, "can not find process");
662+
goto out;
663+
}
664+
665+
kill(exec->pid, (int)json_object_get_number(json_object(value), "signal"));
666+
ret = 0;
667+
out:
668+
json_value_free(value);
669+
return ret;
670+
}
671+
647672
static int hyper_remove_container(struct hyper_pod *pod, char *json, int length)
648673
{
649674
struct hyper_container *c;
@@ -1136,6 +1161,9 @@ static int hyper_ctlmsg_handle(struct hyper_event *he, uint32_t len)
11361161
case SETUPROUTE:
11371162
ret = hyper_cmd_setup_route((char *)buf->data + 8, len - 8);
11381163
break;
1164+
case SIGNALPROCESS:
1165+
ret = hyper_signal_process(pod, (char *)buf->data + 8, len - 8);
1166+
break;
11391167
case GETPOD_DEPRECATED:
11401168
case STOPPOD_DEPRECATED:
11411169
case RESTARTCONTAINER_DEPRECATED:

0 commit comments

Comments
 (0)