[lxc-devel] [lxd/master] terminal fixes

brauner on Github lxc-bot at linuxcontainers.org
Wed Feb 12 09:42:29 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200212/986e394e/attachment.bin>
-------------- next part --------------
From 1cea7fc523c0f1f09b1f24ff18d24510c00f2d1d Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 12 Feb 2020 09:27:21 +0100
Subject: [PATCH 1/2] shared: get_poll_revents(): handle EAGAIN in addition to
 EINTR

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 shared/util_linux_cgo.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/shared/util_linux_cgo.go b/shared/util_linux_cgo.go
index bcf7e4f1cb..1914ff1002 100644
--- a/shared/util_linux_cgo.go
+++ b/shared/util_linux_cgo.go
@@ -119,7 +119,7 @@ int get_poll_revents(int lfd, int timeout, int flags, int *revents, int *saved_e
 again:
 	ret = poll(&pfd, 1, timeout);
 	if (ret < 0) {
-		if (errno == EINTR)
+		if (errno == EINTR || errno == EAGAIN)
 			goto again;
 
 		*saved_errno = errno;

From 0f39ee55f525f7359a1bde32f1c519fbcfd0e883 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 12 Feb 2020 10:41:21 +0100
Subject: [PATCH 2/2] lxc: send SIGTERM when there's no controlling terminal

This let's e.g. lxc exec -- su -l exit when the terminal is closed.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxc/exec_unix.go | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lxc/exec_unix.go b/lxc/exec_unix.go
index 02429b9d36..91b62ad209 100644
--- a/lxc/exec_unix.go
+++ b/lxc/exec_unix.go
@@ -55,10 +55,17 @@ func (c *cmdExec) controlSocketHandler(control *websocket.Conn) {
 				return
 			}
 		case unix.SIGHUP:
+			file, err := os.OpenFile("/dev/tty", os.O_RDONLY|unix.O_NOCTTY|unix.O_NOFOLLOW|unix.O_CLOEXEC, 0666)
+			if err == nil {
+				file.Close()
+				err = c.forwardSignal(control, unix.SIGHUP)
+			} else {
+				err = c.forwardSignal(control, unix.SIGTERM)
+				sig = unix.SIGTERM
+			}
 			logger.Debugf("Received '%s signal', forwarding to executing program.", sig)
-			err := c.forwardSignal(control, unix.SIGHUP)
 			if err != nil {
-				logger.Debugf("Failed to forward signal '%s'.", unix.SIGHUP)
+				logger.Debugf("Failed to forward signal '%s'.", sig)
 				return
 			}
 		case unix.SIGINT:


More information about the lxc-devel mailing list