introduce hyper_exec_process()

Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
This commit is contained in:
Lai Jiangshan
2016-06-05 23:25:21 +08:00
parent c3eee6616f
commit 193c1cc97e
3 changed files with 15 additions and 34 deletions
+1 -31
View File
@@ -596,37 +596,7 @@ static int hyper_container_init(void *data)
}
hyper_send_type(arg->pipe[1], READY);
if (container->exec.workdir && chdir(container->exec.workdir) < 0) {
perror("change work directory failed");
return -1;
}
if (hyper_setup_exec_user(&container->exec) < 0) {
fprintf(stderr, "setup exec user failed\n");
goto fail;
}
// set the container env
if (hyper_setup_env(container->exec.envs, container->exec.envs_num) < 0) {
fprintf(stdout, "setup env failed\n");
goto fail;
}
if (hyper_dup_exec_tty(&container->exec) < 0) {
fprintf(stdout, "setup tty failed\n");
goto fail;
}
execvp(container->exec.argv[0], container->exec.argv);
perror("exec container command failed");
/* the exit codes follow the `chroot` standard,
see docker/docs/reference/run.md#exit-status */
if (errno == ENOENT)
_exit(127);
else if (errno == EACCES)
_exit(126);
hyper_exec_process(&container->exec);
fail:
hyper_send_type(arg->pipe[1], ERROR);
+13 -3
View File
@@ -585,6 +585,18 @@ static int hyper_do_exec_cmd(void *data)
goto exit;
}
hyper_exec_process(exec);
exit:
_exit(125);
out:
hyper_send_type(arg->pipe[1], ret ? ERROR : READY);
_exit(ret);
}
// do the exec, no return
void hyper_exec_process(struct hyper_exec *exec)
{
if (exec->workdir && chdir(exec->workdir) < 0) {
perror("change work directory failed");
goto exit;
@@ -618,10 +630,8 @@ static int hyper_do_exec_cmd(void *data)
}
exit:
fflush(stdout);
_exit(125);
out:
hyper_send_type(arg->pipe[1], ret ? ERROR : READY);
_exit(ret);
}
static void hyper_free_exec(struct hyper_exec *exec)
+1
View File
@@ -49,6 +49,7 @@ int hyper_release_exec(struct hyper_exec *, struct hyper_pod *);
int hyper_container_execcmd(struct hyper_pod *pod);
int hyper_setup_exec_tty(struct hyper_exec *e);
int hyper_dup_exec_tty(struct hyper_exec *e);
void hyper_exec_process(struct hyper_exec *e);
struct hyper_exec *hyper_find_exec_by_pid(struct list_head *head, int pid);
struct hyper_exec *hyper_find_exec_by_seq(struct hyper_pod *pod, uint64_t seq);
int hyper_setup_exec_user(struct hyper_exec *e);