From 80ce7650f4b5da646f9851844a6b0fa6b947f2ec Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Wed, 6 Jan 2016 16:25:38 +0800 Subject: [PATCH] Fix container exit without restore terminal Signed-off-by: Lei Jitang --- ctr/container.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ctr/container.go b/ctr/container.go index 8b0758f..a30cb0e 100644 --- a/ctr/container.go +++ b/ctr/container.go @@ -126,19 +126,24 @@ var StartCommand = cli.Command{ fatal(err.Error(), 1) } if context.Bool("attach") { - go func() { - io.Copy(stdin, os.Stdin) + restoreAndCloseStdin := func() { if state != nil { term.RestoreTerminal(os.Stdin.Fd(), state) } stdin.Close() + } + go func() { + io.Copy(stdin, os.Stdin) + restoreAndCloseStdin() }() for { e, err := events.Recv() if err != nil { + restoreAndCloseStdin() fatal(err.Error(), 1) } if e.Id == id && e.Type == "exit" { + restoreAndCloseStdin() os.Exit(int(e.Status)) } }