diff --git a/src/exec.c b/src/exec.c index dae3437..5b0b595 100644 --- a/src/exec.c +++ b/src/exec.c @@ -631,28 +631,38 @@ static void hyper_free_exec(struct hyper_exec *exec) int hyper_exec_cmd(char *json, int length) { struct hyper_exec *exec; - struct hyper_pod *pod = &global_pod; - int pipe[2] = {-1, -1}; - int pid, ret = -1; - uint32_t type; fprintf(stdout, "call hyper_exec_cmd, json %s, len %d\n", json, length); exec = hyper_parse_execcmd(json, length); if (exec == NULL) { fprintf(stderr, "parse exec cmd failed\n"); - goto out; + return -1; } + int ret = hyper_run_process(exec); + if (ret < 0) { + hyper_free_exec(exec); + } + return ret; +} + +int hyper_run_process(struct hyper_exec *exec) +{ + struct hyper_pod *pod = &global_pod; + int pipe[2] = {-1, -1}; + int pid, ret = -1; + uint32_t type; + if (exec->argv == NULL) { fprintf(stderr, "cmd is %p, seq %" PRIu64 ", container %s\n", exec->argv, exec->seq, exec->id); - goto free_exec; + goto out; } if (hyper_setup_exec_tty(exec) < 0) { fprintf(stderr, "setup exec tty failed\n"); - goto free_exec; + goto out; } if (hyper_watch_exec_pty(exec, pod) < 0) { @@ -699,8 +709,6 @@ close_tty: close(exec->stdinfd); close(exec->stdoutfd); close(exec->stderrfd); -free_exec: - hyper_free_exec(exec); goto out; } diff --git a/src/exec.h b/src/exec.h index f176262..54e35cf 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); +int hyper_run_process(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);