2018-02-05 21:05:59 +00:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2014-07-31 20:53:22 +00:00
|
|
|
|
2016-03-18 18:50:19 +00:00
|
|
|
import (
|
2017-09-22 13:52:41 +00:00
|
|
|
"context"
|
2022-10-05 14:28:35 +00:00
|
|
|
"errors"
|
|
|
|
"strconv"
|
2018-06-08 03:07:48 +00:00
|
|
|
"time"
|
2023-05-27 16:04:59 +00:00
|
|
|
|
2023-08-26 13:24:46 +00:00
|
|
|
"github.com/docker/docker/api/types/events"
|
2023-05-27 16:04:59 +00:00
|
|
|
"github.com/docker/docker/errdefs"
|
2016-03-18 18:50:19 +00:00
|
|
|
)
|
2015-11-05 21:40:42 +00:00
|
|
|
|
2015-07-30 21:01:53 +00:00
|
|
|
// ContainerResize changes the size of the TTY of the process running
|
|
|
|
// in the container with the given name to the given height and width.
|
2015-09-29 17:51:40 +00:00
|
|
|
func (daemon *Daemon) ContainerResize(name string, height, width int) error {
|
2015-12-11 17:39:28 +00:00
|
|
|
container, err := daemon.GetContainer(name)
|
2014-09-15 22:56:47 +00:00
|
|
|
if err != nil {
|
2015-03-25 07:44:12 +00:00
|
|
|
return err
|
2014-09-15 22:56:47 +00:00
|
|
|
}
|
2015-05-02 01:03:35 +00:00
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
container.Lock()
|
|
|
|
tsk, err := container.GetRunningTask()
|
|
|
|
container.Unlock()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2015-11-05 21:40:42 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
if err = tsk.Resize(context.Background(), uint32(width), uint32(height)); err == nil {
|
2023-08-26 13:24:46 +00:00
|
|
|
daemon.LogContainerEventWithAttributes(container, events.ActionResize, map[string]string{
|
2022-10-05 14:28:35 +00:00
|
|
|
"height": strconv.Itoa(height),
|
|
|
|
"width": strconv.Itoa(width),
|
2023-08-26 16:25:27 +00:00
|
|
|
})
|
2015-11-03 17:33:13 +00:00
|
|
|
}
|
|
|
|
return err
|
2015-05-02 01:03:35 +00:00
|
|
|
}
|
|
|
|
|
2015-07-30 21:01:53 +00:00
|
|
|
// ContainerExecResize changes the size of the TTY of the process
|
|
|
|
// running in the exec with the given name to the given height and
|
|
|
|
// width.
|
2015-09-29 17:51:40 +00:00
|
|
|
func (daemon *Daemon) ContainerExecResize(name string, height, width int) error {
|
2016-03-18 18:50:19 +00:00
|
|
|
ec, err := daemon.getExecConfig(name)
|
2015-05-02 01:03:35 +00:00
|
|
|
if err != nil {
|
2015-03-25 07:44:12 +00:00
|
|
|
return err
|
2014-09-15 22:56:47 +00:00
|
|
|
}
|
2019-01-09 18:24:03 +00:00
|
|
|
|
2018-06-08 03:07:48 +00:00
|
|
|
// TODO: the timeout is hardcoded here, it would be more flexible to make it
|
|
|
|
// a parameter in resize request context, which would need API changes.
|
2019-01-09 18:24:03 +00:00
|
|
|
timeout := time.NewTimer(10 * time.Second)
|
|
|
|
defer timeout.Stop()
|
|
|
|
|
2018-06-08 03:07:48 +00:00
|
|
|
select {
|
|
|
|
case <-ec.Started:
|
2023-05-27 16:04:59 +00:00
|
|
|
// An error may have occurred, so ec.Process may be nil.
|
|
|
|
if ec.Process == nil {
|
|
|
|
return errdefs.InvalidParameter(errors.New("exec process is not started"))
|
|
|
|
}
|
2022-05-10 19:59:00 +00:00
|
|
|
return ec.Process.Resize(context.Background(), uint32(width), uint32(height))
|
2019-01-09 18:24:03 +00:00
|
|
|
case <-timeout.C:
|
2022-10-05 14:28:35 +00:00
|
|
|
return errors.New("timeout waiting for exec session ready")
|
2018-06-08 03:07:48 +00:00
|
|
|
}
|
2014-09-15 22:56:47 +00:00
|
|
|
}
|