From 11c62c32a63e9e3d9ab9d4b125c55cd978b61944 Mon Sep 17 00:00:00 2001 From: Wang Xu Date: Mon, 3 Apr 2017 12:39:20 +0800 Subject: [PATCH] don't interrupt iostream when exec vm process finished MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #555 before patch: ``` ➜ sudo ./hyperctl exec -m busybox-2857568349 sh -c 'echo aaa' ➜ sudo ./hyperctl exec -m busybox-2857568349 sh -c 'echo aaa' aaa ➜ sudo ./hyperctl exec -m busybox-2857568349 sh -c 'echo aaa' ➜ sudo ./hyperctl exec -m busybox-2857568349 sh -c 'echo aaa' ➜ sudo ./hyperctl exec -m busybox-2857568349 sh -c 'echo aaa' ➜ sudo ./hyperctl exec -m busybox-2857568349 sh -c 'echo aaa' aaa ➜ sudo ./hyperctl exec -m busybox-2857568349 sh -c 'echo aaa' aaa ➜ sudo ./hyperctl exec -m busybox-2857568349 sh -c 'echo aaa' aaa ➜ ``` after this patch: ``` ➜ for i in `seq 1 1000`; do x=$(sudo ./hyperctl exec -m busybox-1102769742 sh -c 'echo aaa'); [ "${x}x" != "aaax" ] && echo "fail" ; done ➜ ``` Signed-off-by: Wang Xu --- daemon/pod/exec.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/daemon/pod/exec.go b/daemon/pod/exec.go index c37e0f84..9288bb6d 100644 --- a/daemon/pod/exec.go +++ b/daemon/pod/exec.go @@ -206,9 +206,16 @@ func (p *XPod) CleanupExecs() { } func (p *XPod) ExecVM(cmd string, stdin io.ReadCloser, stdout, stderr io.WriteCloser) (int, error) { - return p.sandbox.HyperstartExec(cmd, &hypervisor.TtyIO{ - Stdin: stdin, + wReader := &waitClose{ReadCloser: stdin, wait: make(chan bool)} + tty := &hypervisor.TtyIO{ + Stdin: wReader, Stdout: stdout, Stderr: stderr, - }) + } + res, err := p.sandbox.HyperstartExec(cmd, tty) + if err != nil { + return res, err + } + <-wReader.wait + return res, err }