Skip to content

Commit

Permalink
fixes no such exec error when tty resize
Browse files Browse the repository at this point in the history
Signed-off-by: Lifubang <lifubang@acmcoder.com>
  • Loading branch information
lifubang committed Oct 9, 2018
1 parent 57bc65c commit b238eb9
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions cli/command/container/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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" {
Expand All @@ -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
}

Expand Down

0 comments on commit b238eb9

Please sign in to comment.