From 9728b236ed77d60ab961fc83134ba519d6c8e597 Mon Sep 17 00:00:00 2001 From: Blallo Date: Fri, 3 May 2019 10:32:18 +0200 Subject: [PATCH] Clean sockets at exit. --- cmd/circologd/main.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/circologd/main.go b/cmd/circologd/main.go index 308b0ef..31821e7 100644 --- a/cmd/circologd/main.go +++ b/cmd/circologd/main.go @@ -17,12 +17,18 @@ import ( syslog "gopkg.in/mcuadros/go-syslog.v2" ) +var socketsToRemove []string + func cleanSocket(socket string) { if err := os.Remove(socket); err != nil { fmt.Fprintln(os.Stderr, "Error cleaning", socket, ":", err) } } +func removeAtExit(socket string) { + socketsToRemove = append(socketsToRemove, socket) +} + func main() { var err error var logFmt formatter.SyslogRFC @@ -77,7 +83,7 @@ func main() { fmt.Fprintln(os.Stderr, "Error binding HTTP unix domain socket", err) return } - defer cleanSocket(*querySocket) + removeAtExit(*querySocket) go func() { if err := httpQueryServer.Serve(unixListener); err != nil && err != http.ErrServerClosed { fmt.Fprintln(os.Stderr, "error binding", *querySocket, ":", err) @@ -102,7 +108,7 @@ func main() { fmt.Fprintln(os.Stderr, "Error binding HTTP unix domain socket", err) return } - defer cleanSocket(*ctlSocket) + removeAtExit(*ctlSocket) go func() { if err := httpCtlServer.Serve(unixListener); err != nil && err != http.ErrServerClosed { fmt.Fprintln(os.Stderr, "error binding:", err) @@ -152,6 +158,9 @@ func main() { if err := httpCtlServer.Shutdown(nil); err != nil { fmt.Fprintln(os.Stderr, "Error closing control server:", err) } + for _, socket := range socketsToRemove { + cleanSocket(socket) + } return } }