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

Commit 8eb56e2

Browse files
committed
add process id
Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
1 parent b548fbb commit 8eb56e2

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/exec.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,19 @@ static int hyper_release_exec(struct hyper_exec *exec)
713713
return 0;
714714
}
715715

716+
struct hyper_exec *hyper_find_exec_by_name(struct hyper_pod *pod, const char *process)
717+
{
718+
struct hyper_exec *exec;
719+
720+
list_for_each_entry(exec, &pod->exec_head, list) {
721+
if (strcmp(exec->id, process) == 0) {
722+
return exec;
723+
}
724+
}
725+
726+
return NULL;
727+
}
728+
716729
struct hyper_exec *hyper_find_exec_by_pid(struct list_head *head, int pid)
717730
{
718731
struct hyper_exec *exec;

src/exec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct hyper_exec {
2727

2828
// configs
2929
char *container_id;
30+
char *id;
3031
char *user;
3132
char *group;
3233
char **additional_groups;
@@ -45,6 +46,7 @@ struct hyper_pod;
4546

4647
int hyper_exec_cmd(char *json, int length);
4748
int hyper_run_process(struct hyper_exec *e);
49+
struct hyper_exec *hyper_find_exec_by_name(struct hyper_pod *pod, const char *process);
4850
struct hyper_exec *hyper_find_exec_by_pid(struct list_head *head, int pid);
4951
struct hyper_exec *hyper_find_exec_by_seq(struct hyper_pod *pod, uint64_t seq);
5052
int hyper_handle_exec_exit(struct hyper_pod *pod, int pid, uint8_t code);

src/parse.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ void hyper_cleanup_exec(struct hyper_exec *exec)
188188
free(exec->container_id);
189189
exec->container_id = NULL;
190190

191+
free(exec->id);
192+
exec->id = NULL;
193+
191194
free(exec->user);
192195
exec->user = NULL;
193196
free(exec->group);
@@ -474,7 +477,11 @@ static int hyper_parse_process(struct hyper_exec *exec, char *json, jsmntok_t *t
474477
for (j = 0; j < toks_size; j++) {
475478
t = &toks[i];
476479
dprintf(stdout, "%d name %s\n", i, json_token_str(json, t));
477-
if (json_token_streq(json, t, "user") && t->size == 1) {
480+
if (json_token_streq(json, t, "id") && t->size == 1) {
481+
exec->id = (json_token_str(json, &toks[++i]));
482+
dprintf(stdout, "container process id %s\n", exec->id);
483+
i++;
484+
} else if (json_token_streq(json, t, "user") && t->size == 1) {
478485
exec->user = (json_token_str(json, &toks[++i]));
479486
dprintf(stdout, "container process user %s\n", exec->user);
480487
i++;

0 commit comments

Comments
 (0)