From 4e830d77b4402d9d088f0cedfce18cd65339a6bf Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Sun, 25 Sep 2016 10:08:21 +0800 Subject: [PATCH] check exec->seq and exec->id earlier Signed-off-by: Lai Jiangshan --- src/exec.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/exec.c b/src/exec.c index 6e0d0ee..b3e0dcf 100644 --- a/src/exec.c +++ b/src/exec.c @@ -341,11 +341,6 @@ static int hyper_setup_exec_tty(struct hyper_exec *e) int ptymaster; char ptmx[512], path[512]; - if (e->seq == 0) { - fprintf(stderr, "e->seq should be set\n"); - return -1; - } - if (!e->tty) { // don't use tty for stdio return hyper_setup_exec_notty(e); } @@ -361,16 +356,9 @@ static int hyper_setup_exec_tty(struct hyper_exec *e) e->stderrfd = errpipe[1]; } - if (e->id) { - if (sprintf(path, "/tmp/hyper/%s/devpts/", e->id) < 0) { - fprintf(stderr, "get ptmx path failed\n"); - return -1; - } - } else { - if (sprintf(path, "/dev/pts/") < 0) { - fprintf(stderr, "get ptmx path failed\n"); - return -1; - } + if (sprintf(path, "/tmp/hyper/%s/devpts/", e->id) < 0) { + fprintf(stderr, "get ptmx path failed\n"); + return -1; } if (sprintf(ptmx, "%s/ptmx", path) < 0) { @@ -464,9 +452,6 @@ static int hyper_watch_exec_pty(struct hyper_exec *exec, struct hyper_pod *pod) fprintf(stdout, "hyper_init_event container pts event %p, ops %p, fd %d\n", &exec->stdinev, &in_ops, exec->stdinev.fd); - if (exec->seq == 0) - return 0; - if (hyper_init_event(&exec->stdinev, &in_ops, pod) < 0 || hyper_add_event(ctl.efd, &exec->stdinev, EPOLLOUT) < 0) { fprintf(stderr, "add container stdin event failed\n"); @@ -620,7 +605,7 @@ int hyper_run_process(struct hyper_exec *exec) int pid, ret = -1; uint32_t type; - if (exec->argv == NULL) { + if (exec->argv == NULL || exec->seq == 0 || exec->id == NULL || strlen(exec->id) == 0) { fprintf(stderr, "cmd is %p, seq %" PRIu64 ", container %s\n", exec->argv, exec->seq, exec->id); goto out;