From 51dc391bc04c32b689ab64fb28e49d89c4fa97db Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Mon, 4 Jul 2016 21:58:05 +0800 Subject: [PATCH] all exec should have container id Signed-off-by: Lai Jiangshan --- src/exec.c | 37 +++++++++++++++++-------------------- src/parse.c | 5 +++++ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/exec.c b/src/exec.c index 8cab953..b78de2f 100644 --- a/src/exec.c +++ b/src/exec.c @@ -540,27 +540,24 @@ static int hyper_do_exec_cmd(void *data) struct hyper_exec *exec = arg->exec; struct hyper_pod *pod = arg->pod; int pid, ret = -1; + char path[512]; + int pidns; - if (exec->id) { - char path[512]; - int pidns; - - sprintf(path, "/proc/%d/ns/pid", pod->init_pid); - pidns = open(path, O_RDONLY| O_CLOEXEC); - if (pidns < 0) { - perror("fail to open pidns of pod init"); - goto out; - } - - /* enter pidns of pod init, so the children of this process will run in - * pidns of pod init, see man 2 setns */ - if (setns(pidns, CLONE_NEWPID) < 0) { - perror("enter pidns of pod init failed"); - goto out; - } - close(pidns); + sprintf(path, "/proc/%d/ns/pid", pod->init_pid); + pidns = open(path, O_RDONLY| O_CLOEXEC); + if (pidns < 0) { + perror("fail to open pidns of pod init"); + goto out; } + /* enter pidns of pod init, so the children of this process will run in + * pidns of pod init, see man 2 setns */ + if (setns(pidns, CLONE_NEWPID) < 0) { + perror("enter pidns of pod init failed"); + goto out; + } + close(pidns); + if (hyper_watch_exec_pty(exec, pod) < 0) { fprintf(stderr, "add pts master event failed\n"); goto out; @@ -580,7 +577,7 @@ static int hyper_do_exec_cmd(void *data) goto out; } - if (exec->id && hyper_enter_container(pod, exec) < 0) { + if (hyper_enter_container(pod, exec) < 0) { fprintf(stderr, "enter container ns failed\n"); goto exit; } @@ -899,7 +896,7 @@ int hyper_handle_exec_exit(struct hyper_pod *pod, int pid, uint8_t code) } fprintf(stdout, "%s exec exit pid %d, seq %" PRIu64 ", container %s\n", - __func__, exec->pid, exec->seq, exec->id ? exec->id : "pod"); + __func__, exec->pid, exec->seq, exec->id); exec->code = code; exec->exit = 1; diff --git a/src/parse.c b/src/parse.c index 1355f47..0ea2b7e 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1383,6 +1383,11 @@ realloc: } } + if (exec->id == NULL || strlen(exec->id) == 0) { + fprintf(stderr, "execcmd format error, has no container id\n"); + goto fail; + } + if (exec->seq == 0) { fprintf(stderr, "execcmd format error, has no seq\n"); goto fail;