summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2018-05-17 10:42:26 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2018-05-17 13:26:16 +0000
commit3f0e2367c222fe362031f806f002fb8a62be6360 (patch)
treecc513735c9e97bba28cf3c992296c3a55ec776e5 /cmd
parent624660c1b3869bdd6b3342f5924e813f32a81b4a (diff)
downloadpodman-3f0e2367c222fe362031f806f002fb8a62be6360.tar.gz
podman-3f0e2367c222fe362031f806f002fb8a62be6360.tar.bz2
podman-3f0e2367c222fe362031f806f002fb8a62be6360.zip
libpod: fix panic when using -t and the process fails to start
We were closing resize both on the receiver and the sender side. This was racy as the sender might have written to a closed channel. If the container could not be created, the attach exited immediately causing the channel to be closed before the write from resizeTty. Change the logic to close only from the senderSide and add another channel to notify the resizeTty goroutine when the container exited. Closes: https://github.com/projectatomic/libpod/issues/785 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com> Closes: #787 Approved by: mheon
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/utils.go26
1 files changed, 21 insertions, 5 deletions
diff --git a/cmd/podman/utils.go b/cmd/podman/utils.go
index 48b30d274..227426c18 100644
--- a/cmd/podman/utils.go
+++ b/cmd/podman/utils.go
@@ -25,7 +25,12 @@ func attachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys
if haveTerminal && ctr.Spec().Process.Terminal {
logrus.Debugf("Handling terminal attach")
- resizeTty(resize)
+ resizeTerminate := make(chan interface{})
+ defer func() {
+ resizeTerminate <- true
+ close(resizeTerminate)
+ }()
+ resizeTty(resize, resizeTerminate)
oldTermState, err := term.SaveState(os.Stdin.Fd())
if err != nil {
@@ -76,7 +81,12 @@ func startAttachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detac
if haveTerminal && ctr.Spec().Process.Terminal {
logrus.Debugf("Handling terminal attach")
- resizeTty(resize)
+ resizeTerminate := make(chan interface{})
+ defer func() {
+ resizeTerminate <- true
+ close(resizeTerminate)
+ }()
+ resizeTty(resize, resizeTerminate)
oldTermState, err := term.SaveState(os.Stdin.Fd())
if err != nil {
@@ -131,7 +141,7 @@ func startAttachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detac
}
// Helper for prepareAttach - set up a goroutine to generate terminal resize events
-func resizeTty(resize chan remotecommand.TerminalSize) {
+func resizeTty(resize chan remotecommand.TerminalSize, resizeTerminate chan interface{}) {
sigchan := make(chan os.Signal, 1)
gosignal.Notify(sigchan, signal.SIGWINCH)
sendUpdate := func() {
@@ -150,8 +160,14 @@ func resizeTty(resize chan remotecommand.TerminalSize) {
// Update the terminal size immediately without waiting
// for a SIGWINCH to get the correct initial size.
sendUpdate()
- for range sigchan {
- sendUpdate()
+ for {
+ select {
+ case <-resizeTerminate:
+ return
+
+ case <-sigchan:
+ sendUpdate()
+ }
}
}()
}