diff options
author | Paul Holzinger <pholzing@redhat.com> | 2021-06-15 11:05:00 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2021-06-16 16:43:30 +0200 |
commit | 666f555aa52b9f82da9d6ca64cf11e4f5e1e78e8 (patch) | |
tree | 0175dbf916bdb7d4722890191bb5f523f64b202f /libpod/oci_attach_linux.go | |
parent | e2f51eeb0693eda026fa509a9decfbdd7e0b74a8 (diff) | |
download | podman-666f555aa52b9f82da9d6ca64cf11e4f5e1e78e8.tar.gz podman-666f555aa52b9f82da9d6ca64cf11e4f5e1e78e8.tar.bz2 podman-666f555aa52b9f82da9d6ca64cf11e4f5e1e78e8.zip |
Fix resize race with podman exec -it
When starting a process with `podman exec -it` the terminal is resized
after the process is started. To fix this allow exec start to accept the
terminal height and width as parameter and let it resize right before
the process is started.
Fixes #10560
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'libpod/oci_attach_linux.go')
-rw-r--r-- | libpod/oci_attach_linux.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/libpod/oci_attach_linux.go b/libpod/oci_attach_linux.go index b5040de3e..de435b58a 100644 --- a/libpod/oci_attach_linux.go +++ b/libpod/oci_attach_linux.go @@ -94,17 +94,18 @@ func (c *Container) attach(streams *define.AttachStreams, keys string, resize <- // this ensures attachToExec gets all of the output of the called process // conmon will then send the exit code of the exec process, or an error in the exec session // startFd must be the input side of the fd. +// newSize resizes the tty to this size before the process is started, must be nil if the exec session has no tty // conmon will wait to start the exec session until the parent process has setup the console socket. // Once attachToExec successfully attaches to the console socket, the child conmon process responsible for calling runtime exec // will read from the output side of start fd, thus learning to start the child process. // Thus, the order goes as follow: // 1. conmon parent process sets up its console socket. sends on attachFd -// 2. attachToExec attaches to the console socket after reading on attachFd +// 2. attachToExec attaches to the console socket after reading on attachFd and resizes the tty // 3. child waits on startFd for attachToExec to attach to said console socket // 4. attachToExec sends on startFd, signalling it has attached to the socket and child is ready to go // 5. child receives on startFd, runs the runtime exec command // attachToExec is responsible for closing startFd and attachFd -func (c *Container) attachToExec(streams *define.AttachStreams, keys *string, sessionID string, startFd, attachFd *os.File) error { +func (c *Container) attachToExec(streams *define.AttachStreams, keys *string, sessionID string, startFd, attachFd *os.File, newSize *define.TerminalSize) error { if !streams.AttachOutput && !streams.AttachError && !streams.AttachInput { return errors.Wrapf(define.ErrInvalidArg, "must provide at least one stream to attach to") } @@ -137,6 +138,14 @@ func (c *Container) attachToExec(streams *define.AttachStreams, keys *string, se return err } + // resize before we start the container process + if newSize != nil { + err = c.ociRuntime.ExecAttachResize(c, sessionID, *newSize) + if err != nil { + logrus.Warn("resize failed", err) + } + } + // 2: then attach conn, err := openUnixSocket(sockPath) if err != nil { |