all exec should have container id

Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
This commit is contained in:
Lai Jiangshan
2016-07-04 21:58:05 +08:00
parent 73a9c3e8e9
commit 51dc391bc0
2 changed files with 22 additions and 20 deletions
+17 -20
View File
@@ -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;
+5
View File
@@ -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;