[lxc-devel] [lxd/master] [lxd/main_daemon] Ignore SIGHUP to main daemon

Foxboron on Github lxc-bot at linuxcontainers.org
Tue Jan 21 19:20:01 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 847 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200121/55c50929/attachment.bin>
-------------- next part --------------
From 7897392518ab5b2360292ae5f9435378fefdc1ad Mon Sep 17 00:00:00 2001
From: Morten Linderud <morten at linderud.pw>
Date: Tue, 21 Jan 2020 20:15:02 +0100
Subject: [PATCH] [lxd/main_daemon] Ignore SIGHUP to main daemon

When having open file handlers in a service closed, there are SIGHUPs
sent to them. Currently it seems systemd intercepts these and SIGHUPs
the main process. The process gracefully stops as a result.

This code ensures we are watching SIGHUPs and ignores the signal for the
time being.

Fixes #6743

Signed-off-by: Morten Linderud <morten at linderud.pw>
---
 lxd/main_daemon.go | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/lxd/main_daemon.go b/lxd/main_daemon.go
index 64876128a9..e7b0f2bebd 100644
--- a/lxd/main_daemon.go
+++ b/lxd/main_daemon.go
@@ -72,24 +72,33 @@ func (c *cmdDaemon) Run(cmd *cobra.Command, args []string) error {
 	signal.Notify(ch, unix.SIGINT)
 	signal.Notify(ch, unix.SIGQUIT)
 	signal.Notify(ch, unix.SIGTERM)
+	signal.Notify(ch, unix.SIGHUP)
 
 	s := d.State()
-	select {
-	case sig := <-ch:
-		if sig == unix.SIGPWR {
-			logger.Infof("Received '%s signal', shutting down containers", sig)
+	for {
+		select {
+		case sig := <-ch:
+			if sig == unix.SIGPWR {
+				logger.Infof("Received '%s signal', shutting down containers", sig)
+				containersShutdown(s)
+				networkShutdown(s)
+				goto exit
+			} else if sig == unix.SIGHUP {
+				logger.Infof("Received '%s signal', ignoring", sig)
+			} else {
+				logger.Infof("Received '%s signal', exiting", sig)
+				goto exit
+			}
+
+		case <-d.shutdownChan:
+			logger.Infof("Asked to shutdown by API, shutting down containers")
+			d.Kill()
 			containersShutdown(s)
 			networkShutdown(s)
-		} else {
-			logger.Infof("Received '%s signal', exiting", sig)
+			goto exit
 		}
-
-	case <-d.shutdownChan:
-		logger.Infof("Asked to shutdown by API, shutting down containers")
-		d.Kill()
-		containersShutdown(s)
-		networkShutdown(s)
 	}
 
+exit:
 	return d.Stop()
 }


More information about the lxc-devel mailing list