[lxc-devel] [lxd/master] exec: wait until the window size is set

tych0 on Github lxc-bot at linuxcontainers.org
Fri Mar 25 17:45:16 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 760 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160325/5435460d/attachment.bin>
-------------- next part --------------
From 3d29f99a55e95e08235cfa7e4d3dbfdacdc192fe Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Fri, 25 Mar 2016 16:09:57 +0000
Subject: [PATCH] exec: wait until the window size is set

While debugging something else, I noticed that the term size for exec is racy:
if the command happens to run before the goroutine in the client sends the
actual size of the terminal, we just get the default size for the pty.

Let's wait until the window size is set at least once before we do exec. It may
be worth documenting that this needs to happen somewhere, but I'm not sure
where :)

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 lxd/container_exec.go | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lxd/container_exec.go b/lxd/container_exec.go
index 6780089..adcf17a 100644
--- a/lxd/container_exec.go
+++ b/lxd/container_exec.go
@@ -131,6 +131,7 @@ func (s *execWs) Do(op *operation) error {
 
 	if s.interactive {
 		wgEOF.Add(1)
+		windowSizeSet := make(chan bool, 1)
 		go func() {
 			select {
 			case <-s.controlConnected:
@@ -178,6 +179,7 @@ func (s *execWs) Do(op *operation) error {
 					}
 
 					err = shared.SetSize(int(ptys[0].Fd()), winchWidth, winchHeight)
+					windowSizeSet <- true
 					if err != nil {
 						shared.Debugf("Failed to set window size to: %dx%d", winchWidth, winchHeight)
 						continue
@@ -190,6 +192,9 @@ func (s *execWs) Do(op *operation) error {
 				}
 			}
 		}()
+
+		<-windowSizeSet
+
 		go func() {
 			readDone, writeDone := shared.WebsocketMirror(s.conns[0], ptys[0], ptys[0])
 			<-readDone


More information about the lxc-devel mailing list