From aad69e9603c6238265b25e925f0cbdc54f1f3e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20I=C3=B1iguez=20Goia?= Date: Mon, 2 Nov 2020 01:40:52 +0100 Subject: [PATCH] close log file handles when applying a configuration change we were leaking descriptors. --- daemon/ui/config.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/daemon/ui/config.go b/daemon/ui/config.go index 4386689bbc..c59d11cb09 100644 --- a/daemon/ui/config.go +++ b/daemon/ui/config.go @@ -68,13 +68,17 @@ func (c *Client) loadConfiguration(rawConfig []byte) bool { defer config.Unlock() if err := json.Unmarshal(rawConfig, &config); err != nil { - fmt.Errorf("Error parsing configuration %s: %s", configFile, err) + log.Error("Error parsing configuration %s: %s", configFile, err) return false } // firstly load config level, to detect further errors if any if config.LogLevel != nil { log.SetLogLevel(int(*config.LogLevel)) } + if config.Server.LogFile != "" { + log.Close() + log.OpenFile(config.Server.LogFile) + } if config.Server.Address != "" { tempSocketPath := c.getSocketPath(config.Server.Address) @@ -84,12 +88,6 @@ func (c *Client) loadConfiguration(rawConfig []byte) bool { } c.setSocketPath(tempSocketPath) } - if config.Server.LogFile != "" { - if err := log.OpenFile(config.Server.LogFile); err != nil { - log.Warning("Error opening log file: ", err) - } - } - if config.DefaultAction != "" { clientDisconnectedRule.Action = rule.Action(config.DefaultAction) clientErrorRule.Action = rule.Action(config.DefaultAction)