From 26183926a315bb436060cbcc009b6ac73c39841f Mon Sep 17 00:00:00 2001 From: Gao feng Date: Wed, 21 Oct 2015 12:18:18 +0800 Subject: [PATCH 1/9] do not close ptyfd after set window size Signed-off-by: Gao feng --- src/init.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/init.c b/src/init.c index 8af778b..2b1f410 100644 --- a/src/init.c +++ b/src/init.c @@ -48,7 +48,7 @@ static int hyper_set_win_size(char *json, int length) }; struct winsize size; struct hyper_exec *exec; - char *name, path[128]; + char path[128]; int fd, ret; fprintf(stdout, "call hyper_win_size, json %s, len %d\n", json, length); @@ -57,7 +57,6 @@ static int hyper_set_win_size(char *json, int length) return -1; } - name = ws.tty; if (!ws.tty) { exec = hyper_find_exec_by_seq(&global_pod, ws.seq); if (exec == NULL) { @@ -67,17 +66,18 @@ static int hyper_set_win_size(char *json, int length) fprintf(stdout, "find exec %s, pid is %d, seq is %" PRIu64"\n", exec->id ? exec->id : "pod", exec->pid, ws.seq); - fd = exec->ptyfd; + fd = dup(exec->ptyfd); } else { if (sprintf(path, "/dev/%s", ws.tty) < 0) { fprintf(stderr, "get tty device failed\n"); return -1; } - fd = hyper_open_serial_dev(name); - if (fd < 0) { - fprintf(stderr, "cannot open %s to set term size\n", name); - goto out; - } + fd = hyper_open_serial_dev(path); + } + + if (fd < 0) { + perror("cannot open pty device to set term size"); + goto out; } size.ws_row = ws.row; @@ -85,7 +85,7 @@ static int hyper_set_win_size(char *json, int length) ret = ioctl(fd, TIOCSWINSZ, &size); if (ret < 0) - fprintf(stderr, "cannot ioctl to set %s term size\n", name); + perror("cannot ioctl to set pty device term size"); close(fd); out: From 14f9ba5c3fbb2c18550d36868a8b35f82f3465e7 Mon Sep 17 00:00:00 2001 From: Gao feng Date: Wed, 21 Oct 2015 14:56:10 +0800 Subject: [PATCH 2/9] fix incorrect cleanup when exec failed Signed-off-by: Gao feng --- src/exec.c | 52 +++++++++++++++++++++++++++++++--------------------- src/init.c | 3 +-- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/exec.c b/src/exec.c index 64e42a7..df2beb8 100644 --- a/src/exec.c +++ b/src/exec.c @@ -380,13 +380,12 @@ static int hyper_do_exec_cmd(void *data) exec->pid = pid; fprintf(stdout, "create exec cmd %s pid %d\n", exec->argv[0], pid); - list_add_tail(&exec->list, &pod->exec_head); - if (hyper_watch_exec_pty(exec, pod) < 0) { fprintf(stderr, "add pts master event failed\n"); goto out; } + list_add_tail(&exec->list, &pod->exec_head); ret = 0; goto out; } @@ -418,12 +417,28 @@ out: _exit(ret); } +static void hyper_free_exec(struct hyper_exec *exec) +{ + int i; + + free(exec->id); + + for (i = 0; i < exec->argc; i++) { + //fprintf(stdout, "argv %d %s\n", i, exec->argv[i]); + free(exec->argv[i]); + } + + free(exec->argv); + free(exec); +} + int hyper_exec_cmd(char *json, int length) { struct hyper_exec *exec; struct hyper_pod *pod = &global_pod; int stacksize = getpagesize() * 4; - void *stack = NULL; struct hyper_exec_arg arg = { + void *stack = NULL; + struct hyper_exec_arg arg = { .pod = pod, .exec = NULL, .pipe = {-1, -1}, @@ -442,17 +457,17 @@ int hyper_exec_cmd(char *json, int length) if (exec->argv == NULL) { fprintf(stderr, "cmd is %p, seq %" PRIu64 ", container %s\n", exec->argv, exec->seq, exec->id); - goto out; + goto free_exec; } if (hyper_setup_exec_tty(exec) < 0) { fprintf(stderr, "setup exec tty failed\n"); - goto out; + goto free_exec; } if (pipe2(arg.pipe, O_CLOEXEC) < 0) { perror("create pipe between pod init execcmd failed"); - goto out; + goto close_tty; } arg.exec = exec; @@ -460,7 +475,7 @@ int hyper_exec_cmd(char *json, int length) stack = malloc(stacksize); if (stack == NULL) { perror("fail to allocate stack for container init"); - goto out; + goto close_tty; } pid = clone(hyper_do_exec_cmd, stack + stacksize, CLONE_VM| CLONE_FILES| SIGCHLD, &arg); @@ -468,12 +483,12 @@ int hyper_exec_cmd(char *json, int length) free(stack); if (pid < 0) { perror("clone hyper_do_exec_cmd failed"); - goto out; + goto close_tty; } if (hyper_get_type(arg.pipe[0], &type) < 0 || type != READY) { fprintf(stderr, "hyper init doesn't get execcmd ready message\n"); - return -1; + goto close_tty; } fprintf(stdout, "%s get ready message %"PRIu32 "\n", __func__, type); @@ -481,15 +496,18 @@ int hyper_exec_cmd(char *json, int length) out: close(arg.pipe[0]); close(arg.pipe[1]); - return ret; +close_tty: + close(exec->ptyfd); + close(exec->e.fd); +free_exec: + hyper_free_exec(exec); + goto out; } int hyper_release_exec(struct hyper_exec *exec, struct hyper_pod *pod) { - int i; - if (!exec->exit && exec->seq) { fprintf(stdout, "first user of exec exit\n"); exec->exit = 1; @@ -544,15 +562,7 @@ int hyper_release_exec(struct hyper_exec *exec, return 0; } - free(exec->id); - - for (i = 0; i < exec->argc; i++) { - //fprintf(stdout, "argv %d %s\n", i, exec->argv[i]); - free(exec->argv[i]); - } - - free(exec->argv); - free(exec); + hyper_free_exec(exec); return 0; } diff --git a/src/init.c b/src/init.c index 2b1f410..fdb0452 100644 --- a/src/init.c +++ b/src/init.c @@ -392,18 +392,17 @@ static int hyper_do_start_containers(void *data) for (i = 0; i < pod->c_num; i++) { c = &pod->c[i]; - list_add_tail(&c->exec.list, &pod->exec_head); if (hyper_start_container(c, utsns, ipcns, pod) < 0) { fprintf(stderr, "fail to start container\n"); goto out; } + list_add_tail(&c->exec.list, &pod->exec_head); } ret = 0; out: if (hyper_send_type(arg->ctl_pipe[1], ret ? ERROR : READY) < 0) { fprintf(stderr, "container init send ready message failed\n"); - goto out; } close(pidns); From 1f2b1f58803a91d9a5a43ab63f6e9cff763d983f Mon Sep 17 00:00:00 2001 From: Gao feng Date: Fri, 23 Oct 2015 14:44:15 +0800 Subject: [PATCH 3/9] watch up pty fd before exec cmd exec cmd may exit before hyper init watching it's ptmx fd, so the hup event of ptmx may miss, this will cause the eof message fail to send out. Signed-off-by: Gao feng --- src/container.c | 12 +++++++----- src/event.c | 5 ++--- src/exec.c | 10 +++++----- src/parse.c | 1 + 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/container.c b/src/container.c index 169eb42..cecc51f 100644 --- a/src/container.c +++ b/src/container.c @@ -525,6 +525,11 @@ int hyper_start_container(struct hyper_container *container, goto fail; } + if (hyper_watch_exec_pty(&container->exec, pod) < 0) { + fprintf(stderr, "faile to watch container pty\n"); + goto fail; + } + /* wait for ready message */ if (hyper_get_type(arg.pipe[0], &type) < 0 || type != READY) { fprintf(stderr, "wait for container started failed\n"); @@ -534,17 +539,14 @@ int hyper_start_container(struct hyper_container *container, close(arg.pipe[0]); close(arg.pipe[1]); - if (hyper_watch_exec_pty(&container->exec, pod) < 0) { - fprintf(stderr, "faile to watch container pty\n"); - goto fail; - } - fprintf(stdout, "container %s init pid is %d\n", container->id, pid); return 0; fail: close(arg.pipe[0]); close(arg.pipe[1]); close(container->ns); + hyper_reset_event(&container->exec.e); + hyper_reset_event(&container->exec.errev); container->ns = -1; fprintf(stdout, "container %s init exit code %d\n", container->id, -1); container->exec.code = -1; diff --git a/src/event.c b/src/event.c index a6ec6a7..81b6375 100644 --- a/src/event.c +++ b/src/event.c @@ -14,8 +14,9 @@ void hyper_reset_event(struct hyper_event *de) { free(de->rbuf.data); free(de->wbuf.data); - + close(de->fd); memset(de, 0, sizeof(*de)); + de->fd = -1; } int hyper_init_event(struct hyper_event *de, struct hyper_event_ops *ops, void *arg) @@ -219,8 +220,6 @@ void hyper_event_hup(struct hyper_event *de, int efd) { if (epoll_ctl(efd, EPOLL_CTL_DEL, de->fd, NULL) < 0) perror("epoll_ctl del epoll event failed"); - close(de->fd); - de->fd = -1; hyper_reset_event(de); } diff --git a/src/exec.c b/src/exec.c index df2beb8..3916134 100644 --- a/src/exec.c +++ b/src/exec.c @@ -370,6 +370,11 @@ static int hyper_do_exec_cmd(void *data) } else if (pid > 0) { uint32_t type; + if (hyper_watch_exec_pty(exec, pod) < 0) { + fprintf(stderr, "add pts master event failed\n"); + goto out; + } + if (hyper_get_type(pipe[0], &type) < 0 || type != READY) { fprintf(stderr, "hyper init doesn't get execcmd ready message\n"); hyper_send_type(arg->pipe[1], ERROR); @@ -380,11 +385,6 @@ static int hyper_do_exec_cmd(void *data) exec->pid = pid; fprintf(stdout, "create exec cmd %s pid %d\n", exec->argv[0], pid); - if (hyper_watch_exec_pty(exec, pod) < 0) { - fprintf(stderr, "add pts master event failed\n"); - goto out; - } - list_add_tail(&exec->list, &pod->exec_head); ret = 0; goto out; diff --git a/src/parse.c b/src/parse.c index 98c25eb..a159b31 100644 --- a/src/parse.c +++ b/src/parse.c @@ -227,6 +227,7 @@ static int hyper_parse_container(struct hyper_pod *pod, struct hyper_container * c->exec.code = -1; c->exec.e.fd = -1; c->exec.ptyfd = -1; + c->exec.errfd = -1; c->ns = -1; next_container = toks[i].size; From 11c4d7311bf709eae5a7dd4ff80e660d9d59afdb Mon Sep 17 00:00:00 2001 From: Gao feng Date: Fri, 23 Oct 2015 15:05:38 +0800 Subject: [PATCH 4/9] Dont accept input when cmd alreay exited Signed-off-by: Gao feng --- src/init.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/init.c b/src/init.c index fdb0452..56bdf4a 100644 --- a/src/init.c +++ b/src/init.c @@ -1024,6 +1024,12 @@ static int hyper_ttyfd_handle(struct hyper_event *de, uint32_t len) dprintf(stdout, "find exec %s pid %d, seq is %" PRIu64 "\n", exec->id ? exec->id : "pod", exec->pid, exec->seq); + // if exec is exited, the event fd of exec is invalid. don't accept any input. + if (exec->exit) { + fprintf(stdout, "exec seq %" PRIu64 " exited, don't accept any input\n", exec->seq); + return 0; + } + wbuf = &exec->e.wbuf; size = wbuf->size - wbuf->get; From c126e4079575d2c32b2b74508739a5de7b27ec89 Mon Sep 17 00:00:00 2001 From: Gao feng Date: Fri, 23 Oct 2015 16:40:10 +0800 Subject: [PATCH 5/9] use reference to protect exec structure stdout, stderr and signal loop will try to access exec struct. right now, we don't have reference of exec for stderr handler. so in stderr epoll handler, it may access to the already released exec resource. Signed-off-by: Gao feng --- src/container.c | 19 ++++++++----- src/exec.c | 76 ++++++++++++++++++++++++++++++------------------- src/exec.h | 1 + src/init.c | 1 - src/parse.c | 1 + 5 files changed, 61 insertions(+), 37 deletions(-) diff --git a/src/container.c b/src/container.c index cecc51f..ec7f167 100644 --- a/src/container.c +++ b/src/container.c @@ -505,6 +505,11 @@ int hyper_start_container(struct hyper_container *container, goto fail; } + if (hyper_watch_exec_pty(&container->exec, pod) < 0) { + fprintf(stderr, "faile to watch container pty\n"); + goto fail; + } + stack = malloc(stacksize); if (stack == NULL) { perror("fail to allocate stack for container init"); @@ -518,28 +523,27 @@ int hyper_start_container(struct hyper_container *container, goto fail; } sprintf(path, "/proc/%d/ns/mnt", pid); - container->exec.pid = pid; + container->ns = open(path, O_RDONLY | O_CLOEXEC); if (container->ns < 0) { perror("open container mount ns failed"); goto fail; } - if (hyper_watch_exec_pty(&container->exec, pod) < 0) { - fprintf(stderr, "faile to watch container pty\n"); - goto fail; - } - /* wait for ready message */ if (hyper_get_type(arg.pipe[0], &type) < 0 || type != READY) { fprintf(stderr, "wait for container started failed\n"); goto fail; } + container->exec.pid = pid; + list_add_tail(&container->exec.list, &pod->exec_head); + container->exec.ref++; + close(arg.pipe[0]); close(arg.pipe[1]); - fprintf(stdout, "container %s init pid is %d\n", container->id, pid); + fprintf(stdout, "container %s,init pid %d,ref %d\n", container->id, pid, container->exec.ref); return 0; fail: close(arg.pipe[0]); @@ -551,6 +555,7 @@ fail: fprintf(stdout, "container %s init exit code %d\n", container->id, -1); container->exec.code = -1; container->exec.seq = 0; + container->exec.ref = 0; return -1; } diff --git a/src/exec.c b/src/exec.c index 3916134..70d4215 100644 --- a/src/exec.c +++ b/src/exec.c @@ -18,11 +18,9 @@ #include "util.h" #include "parse.h" -static void pts_hup(struct hyper_event *de, int efd) +static void pts_hup(struct hyper_exec *exec, struct hyper_pod *pod, uint64_t seq) { - struct hyper_pod *pod = de->ptr; struct hyper_buf *buf = &ctl.tty.wbuf; - struct hyper_exec *exec = container_of(de, struct hyper_exec, e); fprintf(stdout, "%s\n", __func__); @@ -32,24 +30,35 @@ static void pts_hup(struct hyper_event *de, int efd) } /* no in event, no more data, send eof */ - hyper_set_be64(buf->data + buf->get, exec->seq); + hyper_set_be64(buf->data + buf->get, seq); hyper_set_be32(buf->data + buf->get + 8, 12); buf->get += 12; - if (buf->get + 12 > buf->size) { - fprintf(stdout, "%s: tty buf full (for stderr)\n", __func__); - } else { - /* no in event, no more data, send eof in stderr */ - hyper_set_be64(buf->data + buf->get, exec->errseq); - hyper_set_be32(buf->data + buf->get + 8, 12); - buf->get += 12; - } - hyper_modify_event(ctl.efd, &ctl.tty, EPOLLIN | EPOLLOUT); hyper_release_exec(exec, pod); } +static void stdout_hup(struct hyper_event *de, int efd) +{ + struct hyper_exec *exec = container_of(de, struct hyper_exec, e); + struct hyper_pod *pod = de->ptr; + + fprintf(stdout, "%s, seq %" PRIu64"\n", __func__, exec->seq); + + return pts_hup(exec, pod, exec->seq); +} + +static void stderr_hup(struct hyper_event *de, int efd) +{ + struct hyper_exec *exec = container_of(de, struct hyper_exec, errev); + struct hyper_pod *pod = de->ptr; + + fprintf(stdout, "%s, seq %" PRIu64"\n", __func__, exec->errseq); + + return pts_hup(exec, pod, exec->errseq); +} + static int pts_loop(struct hyper_event *de, uint64_t seq) { int size = -1; @@ -93,7 +102,7 @@ static int stdout_loop(struct hyper_event *de) struct hyper_event_ops pts_ops = { .read = stdout_loop, - .hup = pts_hup, + .hup = stdout_hup, .write = hyper_event_write, .wbuf_size = 512, /* don't need read buff, the pts data will store in tty buffer */ @@ -108,8 +117,8 @@ static int stderr_loop(struct hyper_event *de) } struct hyper_event_ops err_ops = { - /* don't need to deal with hup, the hup will be dealed by pts*/ .read = stderr_loop, + .hup = stderr_hup, /* don't need read buff, the stderr data will store in tty buffer */ /* don't need write buff, the stderr data is one way */ }; @@ -173,6 +182,8 @@ int hyper_setup_exec_tty(struct hyper_exec *e) e->ptyfd = open(ptmx, O_RDWR | O_NOCTTY | O_CLOEXEC); fprintf(stdout, "get pty device for exec %s\n", ptmx); + fprintf(stdout, "%s pts event %p, fd %d %d\n", + __func__, &e->e, e->e.fd, e->ptyfd); return 0; } @@ -249,16 +260,17 @@ int hyper_watch_exec_pty(struct hyper_exec *exec, struct hyper_pod *pod) fprintf(stderr, "add container pts master event failed\n"); return -1; } + exec->ref++; if (exec->errseq == 0) return 0; - if (hyper_init_event(&exec->errev, &err_ops, NULL) < 0 || + if (hyper_init_event(&exec->errev, &err_ops, pod) < 0 || hyper_add_event(ctl.efd, &exec->errev, EPOLLIN) < 0) { fprintf(stderr, "add container stderr event failed\n"); return -1; } - + exec->ref++; return 0; } @@ -363,6 +375,11 @@ static int hyper_do_exec_cmd(void *data) goto out; } + if (hyper_watch_exec_pty(exec, pod) < 0) { + fprintf(stderr, "add pts master event failed\n"); + goto out; + } + pid = fork(); if (pid < 0) { perror("fail to fork"); @@ -370,11 +387,6 @@ static int hyper_do_exec_cmd(void *data) } else if (pid > 0) { uint32_t type; - if (hyper_watch_exec_pty(exec, pod) < 0) { - fprintf(stderr, "add pts master event failed\n"); - goto out; - } - if (hyper_get_type(pipe[0], &type) < 0 || type != READY) { fprintf(stderr, "hyper init doesn't get execcmd ready message\n"); hyper_send_type(arg->pipe[1], ERROR); @@ -383,9 +395,10 @@ static int hyper_do_exec_cmd(void *data) fprintf(stdout, "hyper init get ready message\n"); exec->pid = pid; - fprintf(stdout, "create exec cmd %s pid %d\n", exec->argv[0], pid); - + //TODO combin ref++ and add to list. list_add_tail(&exec->list, &pod->exec_head); + exec->ref++; + fprintf(stdout, "create exec cmd %s pid %d,ref %d\n", exec->argv[0], pid, exec->ref); ret = 0; goto out; } @@ -499,6 +512,7 @@ out: return ret; close_tty: close(exec->ptyfd); + close(exec->errfd); close(exec->e.fd); free_exec: hyper_free_exec(exec); @@ -508,11 +522,8 @@ free_exec: int hyper_release_exec(struct hyper_exec *exec, struct hyper_pod *pod) { - if (!exec->exit && exec->seq) { - fprintf(stdout, "first user of exec exit\n"); - exec->exit = 1; - close(exec->ptyfd); - exec->ptyfd = -1; + if (--exec->ref != 0) { + fprintf(stdout, "still have %d user of exec\n", exec->ref); return 0; } @@ -614,6 +625,13 @@ int hyper_send_exec_eof(int to, struct hyper_pod *pod, __func__, exec->pid, exec->seq, exec->id ? exec->id : "pod"); exec->code = code; + exec->exit = 1; + + close(exec->ptyfd); + exec->ptyfd = -1; + close(exec->errfd); + exec->errfd = -1; + hyper_release_exec(exec, pod); return 0; diff --git a/src/exec.h b/src/exec.h index 2726e08..2da0dd8 100644 --- a/src/exec.h +++ b/src/exec.h @@ -20,6 +20,7 @@ struct hyper_exec { int errfd; uint8_t code; uint8_t exit; + uint8_t ref; }; struct hyper_pod; diff --git a/src/init.c b/src/init.c index 56bdf4a..fd81cee 100644 --- a/src/init.c +++ b/src/init.c @@ -396,7 +396,6 @@ static int hyper_do_start_containers(void *data) fprintf(stderr, "fail to start container\n"); goto out; } - list_add_tail(&c->exec.list, &pod->exec_head); } ret = 0; diff --git a/src/parse.c b/src/parse.c index a159b31..040016b 100644 --- a/src/parse.c +++ b/src/parse.c @@ -615,6 +615,7 @@ realloc: goto out; exec->ptyfd = -1; + exec->errfd = -1; exec->e.fd = -1; INIT_LIST_HEAD(&exec->list); From cff19ec212da42871cfb78b1c10536e0f716af61 Mon Sep 17 00:00:00 2001 From: Gao feng Date: Fri, 23 Oct 2015 17:42:45 +0800 Subject: [PATCH 6/9] remove pts event from epoll when get hup event fix the multi hup event problem. seams like close event fd doesn't frobid hup event being triggered again. Signed-off-by: Gao feng --- src/exec.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/exec.c b/src/exec.c index 70d4215..4d5c62a 100644 --- a/src/exec.c +++ b/src/exec.c @@ -18,11 +18,24 @@ #include "util.h" #include "parse.h" -static void pts_hup(struct hyper_exec *exec, struct hyper_pod *pod, uint64_t seq) +static void pts_hup(struct hyper_event *de, int efd, int out) { + struct hyper_exec *exec; + struct hyper_pod *pod = de->ptr; struct hyper_buf *buf = &ctl.tty.wbuf; + uint64_t seq; - fprintf(stdout, "%s\n", __func__); + if (out) { + exec = container_of(de, struct hyper_exec, e); + seq = exec->seq; + } else { + exec = container_of(de, struct hyper_exec, errev); + seq = exec->errseq; + } + + fprintf(stdout, "%s, seq %" PRIu64"\n", __func__, seq); + + hyper_event_hup(de, efd); if (buf->get + 12 > buf->size) { fprintf(stdout, "%s: tty buf full\n", __func__); @@ -41,22 +54,14 @@ static void pts_hup(struct hyper_exec *exec, struct hyper_pod *pod, uint64_t seq static void stdout_hup(struct hyper_event *de, int efd) { - struct hyper_exec *exec = container_of(de, struct hyper_exec, e); - struct hyper_pod *pod = de->ptr; - - fprintf(stdout, "%s, seq %" PRIu64"\n", __func__, exec->seq); - - return pts_hup(exec, pod, exec->seq); + fprintf(stdout, "%s\n", __func__); + return pts_hup(de, efd, 1); } static void stderr_hup(struct hyper_event *de, int efd) { - struct hyper_exec *exec = container_of(de, struct hyper_exec, errev); - struct hyper_pod *pod = de->ptr; - - fprintf(stdout, "%s, seq %" PRIu64"\n", __func__, exec->errseq); - - return pts_hup(exec, pod, exec->errseq); + fprintf(stdout, "%s\n", __func__); + return pts_hup(de, efd, 0); } static int pts_loop(struct hyper_event *de, uint64_t seq) @@ -529,10 +534,6 @@ int hyper_release_exec(struct hyper_exec *exec, /* exec has no pty or the pty user already exited */ fprintf(stdout, "last user of exec exit, release\n"); - close(exec->e.fd); - close(exec->errev.fd); - close(exec->ptyfd); - close(exec->errfd); hyper_reset_event(&exec->e); hyper_reset_event(&exec->errev); From 7843001aa7d02bb4d4d6be3f448479a847a8a780 Mon Sep 17 00:00:00 2001 From: Gao feng Date: Fri, 23 Oct 2015 17:53:34 +0800 Subject: [PATCH 7/9] initialize errev fd it can not be 0, 0 is an useful fd, this will cause weird closing of ptmx fd. Signed-off-by: Gao feng --- src/parse.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/parse.c b/src/parse.c index 040016b..dfb11e3 100644 --- a/src/parse.c +++ b/src/parse.c @@ -226,6 +226,7 @@ static int hyper_parse_container(struct hyper_pod *pod, struct hyper_container * c->exec.init = 1; c->exec.code = -1; c->exec.e.fd = -1; + c->exec.errev.fd = -1; c->exec.ptyfd = -1; c->exec.errfd = -1; c->ns = -1; @@ -617,6 +618,7 @@ realloc: exec->ptyfd = -1; exec->errfd = -1; exec->e.fd = -1; + exec->errev.fd = -1; INIT_LIST_HEAD(&exec->list); for (i = 0, j = 0; i < n; i++) { From ae5338bde5d9395f778217fbe240403f3735fd75 Mon Sep 17 00:00:00 2001 From: Gao feng Date: Fri, 23 Oct 2015 21:36:53 +0800 Subject: [PATCH 8/9] do not remove lo device in cleanup net Signed-off-by: Gao feng --- src/net.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/net.c b/src/net.c index bd4a58a..822d18b 100644 --- a/src/net.c +++ b/src/net.c @@ -707,6 +707,11 @@ static int hyper_cleanup_interface(struct rtnl_handle *rth, return -1; } + /* Don't down&remove lo device */ + if (strcmp(iface->device, "lo") == 0) { + return 0; + } + if (hyper_down_nic(rth, iface->ifindex) < 0) { fprintf(stderr, "up device %d failed\n", iface->ifindex); return -1; From 18abe7d9e1ec7aa028330c3b2a70dd8e10314b2a Mon Sep 17 00:00:00 2001 From: Gao feng Date: Fri, 23 Oct 2015 21:58:48 +0800 Subject: [PATCH 9/9] do not cleanup exec in cleanup pod Let pts loop or signal loop do the cleanup job. fix the possible double free of exec. Signed-off-by: Gao feng --- src/container.c | 7 +++++++ src/exec.c | 3 ++- src/init.c | 1 - 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/container.c b/src/container.c index ec7f167..63a2d11 100644 --- a/src/container.c +++ b/src/container.c @@ -631,6 +631,13 @@ void hyper_cleanup_container(struct hyper_pod *pod) } free(c->maps); close(c->ns); + + free(c->exec.id); + for (i = 0; i < c->exec.argc; i++) { + //fprintf(stdout, "argv %d %s\n", i, exec->argv[i]); + free(c->exec.argv[i]); + } + free(c->exec.argv); } free(pod->c); diff --git a/src/exec.c b/src/exec.c index 4d5c62a..95826f2 100644 --- a/src/exec.c +++ b/src/exec.c @@ -637,7 +637,7 @@ int hyper_send_exec_eof(int to, struct hyper_pod *pod, return 0; } - +/* void hyper_cleanup_exec(struct hyper_pod *pod) { struct hyper_exec *exec, *next; @@ -647,3 +647,4 @@ void hyper_cleanup_exec(struct hyper_pod *pod) hyper_release_exec(exec, pod); } } +*/ diff --git a/src/init.c b/src/init.c index fd81cee..58c2ecb 100644 --- a/src/init.c +++ b/src/init.c @@ -938,7 +938,6 @@ static void hyper_cleanup_shared(struct hyper_pod *pod) void hyper_cleanup_pod(struct hyper_pod *pod) { - hyper_cleanup_exec(pod); hyper_cleanup_container(pod); hyper_cleanup_network(pod); hyper_cleanup_shared(pod);