From b238eb97d5e9971c4867d06a94a7c4fa31c0374d Mon Sep 17 00:00:00 2001 From: Lifubang Date: Tue, 9 Oct 2018 09:50:54 +0800 Subject: [PATCH] fixes no such exec error when tty resize Signed-off-by: Lifubang --- cli/command/container/tty.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/cli/command/container/tty.go b/cli/command/container/tty.go index 94bd7a49bfb1..9f4213e4edc2 100644 --- a/cli/command/container/tty.go +++ b/cli/command/container/tty.go @@ -16,9 +16,9 @@ import ( ) // resizeTtyTo resizes tty to specific height and width -func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id string, height, width uint, isExec bool) { +func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id string, height, width uint, isExec bool) error { if height == 0 && width == 0 { - return + return nil } options := types.ResizeOptions{ @@ -36,13 +36,22 @@ func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id strin if err != nil { logrus.Debugf("Error resize: %s", err) } + return err } // MonitorTtySize updates the container tty size when the terminal tty changes size func MonitorTtySize(ctx context.Context, cli command.Cli, id string, isExec bool) error { - resizeTty := func() { + resizeTty := func() error { height, width := cli.Out().GetTtySize() - resizeTtyTo(ctx, cli.Client(), id, height, width, isExec) + return resizeTtyTo(ctx, cli.Client(), id, height, width, isExec) + } + + err := resizeTty() + if err != nil { + go func() { + time.Sleep(10 * time.Millisecond) + resizeTty() + }() } if runtime.GOOS == "windows" { @@ -68,11 +77,6 @@ func MonitorTtySize(ctx context.Context, cli command.Cli, id string, isExec bool } }() } - - go func() { - time.Sleep(time.Millisecond) - resizeTty() - }() return nil }