attach: set the terminal size and handle SIGWINCH

Notify conmon when the terminal size changes.  Use the same notification
to set the correct initial size.

Closes: https://github.com/projectatomic/libpod/issues/351

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #448
Approved by: baude
This commit is contained in:
Giuseppe Scrivano
2018-03-04 14:19:46 +01:00
committed by Atomic Bot
parent 5ca69aaa41
commit bbf9a313c3
2 changed files with 42 additions and 11 deletions

View File

@ -56,17 +56,17 @@ func (c *Container) attachContainerSocket(resize <-chan remotecommand.TerminalSi
term.SetRawTerminal(inputStream.Fd())
}
controlPath := filepath.Join(c.bundlePath(), "ctl")
controlFile, err := os.OpenFile(controlPath, unix.O_WRONLY, 0)
if err != nil {
return errors.Wrapf(err, "failed to open container ctl file")
}
defer controlFile.Close()
kubecontainer.HandleResizing(resize, func(size remotecommand.TerminalSize) {
logrus.Debugf("Received a resize event: %+v", size)
_, err := fmt.Fprintf(controlFile, "%d %d %d\n", 1, size.Height, size.Width)
controlPath := filepath.Join(c.bundlePath(), "ctl")
controlFile, err := os.OpenFile(controlPath, unix.O_WRONLY, 0)
if err != nil {
logrus.Debugf("Could not open ctl file: %v", err)
return
}
defer controlFile.Close()
logrus.Debugf("Received a resize event: %+v", size)
if _, err = fmt.Fprintf(controlFile, "%d %d %d\n", 1, size.Height, size.Width); err != nil {
logrus.Warnf("Failed to write to control file to resize terminal: %v", err)
}
})