From 193c1cc97ed94ad89f5445a580781547e02e2313 Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Sun, 5 Jun 2016 22:46:10 +0800 Subject: [PATCH] introduce hyper_exec_process() Signed-off-by: Lai Jiangshan --- src/container.c | 32 +------------------------------- src/exec.c | 16 +++++++++++++--- src/exec.h | 1 + 3 files changed, 15 insertions(+), 34 deletions(-) diff --git a/src/container.c b/src/container.c index e9939e1..6ef2ad1 100644 --- a/src/container.c +++ b/src/container.c @@ -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); diff --git a/src/exec.c b/src/exec.c index b7c70ad..8cab953 100644 --- a/src/exec.c +++ b/src/exec.c @@ -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) diff --git a/src/exec.h b/src/exec.h index 589668a..f176262 100644 --- a/src/exec.h +++ b/src/exec.h @@ -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);