github.com/rawahars/moby@v24.0.4+incompatible/daemon/resize.go (about) 1 package daemon // import "github.com/docker/docker/daemon" 2 3 import ( 4 "context" 5 "errors" 6 "strconv" 7 "time" 8 9 "github.com/docker/docker/errdefs" 10 ) 11 12 // ContainerResize changes the size of the TTY of the process running 13 // in the container with the given name to the given height and width. 14 func (daemon *Daemon) ContainerResize(name string, height, width int) error { 15 container, err := daemon.GetContainer(name) 16 if err != nil { 17 return err 18 } 19 20 container.Lock() 21 tsk, err := container.GetRunningTask() 22 container.Unlock() 23 if err != nil { 24 return err 25 } 26 27 if err = tsk.Resize(context.Background(), uint32(width), uint32(height)); err == nil { 28 attributes := map[string]string{ 29 "height": strconv.Itoa(height), 30 "width": strconv.Itoa(width), 31 } 32 daemon.LogContainerEventWithAttributes(container, "resize", attributes) 33 } 34 return err 35 } 36 37 // ContainerExecResize changes the size of the TTY of the process 38 // running in the exec with the given name to the given height and 39 // width. 40 func (daemon *Daemon) ContainerExecResize(name string, height, width int) error { 41 ec, err := daemon.getExecConfig(name) 42 if err != nil { 43 return err 44 } 45 46 // TODO: the timeout is hardcoded here, it would be more flexible to make it 47 // a parameter in resize request context, which would need API changes. 48 timeout := time.NewTimer(10 * time.Second) 49 defer timeout.Stop() 50 51 select { 52 case <-ec.Started: 53 // An error may have occurred, so ec.Process may be nil. 54 if ec.Process == nil { 55 return errdefs.InvalidParameter(errors.New("exec process is not started")) 56 } 57 return ec.Process.Resize(context.Background(), uint32(width), uint32(height)) 58 case <-timeout.C: 59 return errors.New("timeout waiting for exec session ready") 60 } 61 }