Fix container exit without restore terminal
Signed-off-by: Lei Jitang <leijitang@huawei.com>
This commit is contained in:
parent
476a54714d
commit
80ce7650f4
1 changed files with 7 additions and 2 deletions
|
@ -126,19 +126,24 @@ var StartCommand = cli.Command{
|
||||||
fatal(err.Error(), 1)
|
fatal(err.Error(), 1)
|
||||||
}
|
}
|
||||||
if context.Bool("attach") {
|
if context.Bool("attach") {
|
||||||
go func() {
|
restoreAndCloseStdin := func() {
|
||||||
io.Copy(stdin, os.Stdin)
|
|
||||||
if state != nil {
|
if state != nil {
|
||||||
term.RestoreTerminal(os.Stdin.Fd(), state)
|
term.RestoreTerminal(os.Stdin.Fd(), state)
|
||||||
}
|
}
|
||||||
stdin.Close()
|
stdin.Close()
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
io.Copy(stdin, os.Stdin)
|
||||||
|
restoreAndCloseStdin()
|
||||||
}()
|
}()
|
||||||
for {
|
for {
|
||||||
e, err := events.Recv()
|
e, err := events.Recv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
restoreAndCloseStdin()
|
||||||
fatal(err.Error(), 1)
|
fatal(err.Error(), 1)
|
||||||
}
|
}
|
||||||
if e.Id == id && e.Type == "exit" {
|
if e.Id == id && e.Type == "exit" {
|
||||||
|
restoreAndCloseStdin()
|
||||||
os.Exit(int(e.Status))
|
os.Exit(int(e.Status))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue