[lxc-devel] [lxd/master] lxc/exec: Fix signal handler for Windows

stgraber on Github lxc-bot at linuxcontainers.org
Fri Jul 7 19:44:08 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170707/7a497c81/attachment.bin>
-------------- next part --------------
From d819d52e60622806e94fcd99ed82e59dc889f42e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 7 Jul 2017 15:43:32 -0400
Subject: [PATCH] lxc/exec: Fix signal handler for Windows
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #3496

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxc/exec_windows.go | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/lxc/exec_windows.go b/lxc/exec_windows.go
index 105219e29..67078df6e 100644
--- a/lxc/exec_windows.go
+++ b/lxc/exec_windows.go
@@ -5,6 +5,8 @@ package main
 import (
 	"io"
 	"os"
+	"os/signal"
+	"syscall"
 
 	"github.com/gorilla/websocket"
 	"github.com/mattn/go-colorable"
@@ -32,11 +34,24 @@ func (c *execCmd) getTERM() (string, bool) {
 }
 
 func (c *execCmd) controlSocketHandler(control *websocket.Conn) {
-	// TODO: figure out what the equivalent of signal.SIGWINCH is on
-	// windows and use that; for now if you resize your terminal it just
-	// won't work quite correctly.
-	err := c.sendTermSize(control)
-	if err != nil {
-		logger.Debugf("error setting term size %s", err)
+	ch := make(chan os.Signal, 10)
+	signal.Notify(ch, os.Interrupt)
+
+	closeMsg := websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")
+	defer control.WriteMessage(websocket.CloseMessage, closeMsg)
+
+	for {
+		sig := <-ch
+		switch sig {
+		case os.Interrupt:
+			logger.Debugf("Received '%s signal', forwarding to executing program.", sig)
+			err := c.forwardSignal(control, syscall.SIGINT)
+			if err != nil {
+				logger.Debugf("Failed to forward signal '%s'.", syscall.SIGINT)
+				return
+			}
+		default:
+			break
+		}
 	}
 }


More information about the lxc-devel mailing list