From 749387bbfac88f884dff2b6fac708f5164809f2b Mon Sep 17 00:00:00 2001 From: Gao feng Date: Wed, 23 Sep 2015 23:07:22 +0800 Subject: [PATCH] fix possible missing eof data It happend that pts_loop reads all of the data before the, SIGCHLD signal being handled, so only hup handler will be triggered, move the sending eof message to hup handler. Signed-off-by: Gao feng --- src/exec.c | 21 +++++++++++++++------ src/init.c | 1 - 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/exec.c b/src/exec.c index bf9fd51..ce56fbe 100644 --- a/src/exec.c +++ b/src/exec.c @@ -20,9 +20,23 @@ static void pts_hup(struct hyper_event *de, int efd) { 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__); + + if (buf->get + 12 > buf->size) { + fprintf(stdout, "%s: tty buf full\n", __func__); + return; + } + + /* no in event, no more data, send eof */ + hyper_set_be64(buf->data + buf->get, exec->seq); + 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); } @@ -45,12 +59,7 @@ static int pts_loop(struct hyper_event *de) return -1; } - if (!exec->exit && size != 0) - break; - - /* container task exited, No more data from pts of container, release exec */ - size = 0; - fprintf(stdout, "%s: get eof from pts of contaienr\n", __func__); + break; } hyper_set_be64(buf->data + buf->get, exec->seq); diff --git a/src/init.c b/src/init.c index 068dffd..7cdbbc0 100644 --- a/src/init.c +++ b/src/init.c @@ -1235,7 +1235,6 @@ static int hyper_loop(void) if (hyper_handle_event(ctl.efd, &events[i]) < 0) return -1; } - hyper_modify_event(ctl.efd, &ctl.sig, EPOLLIN); } free(events);