From a990422953d786d27484fa0806d52a3ff3b66f20 Mon Sep 17 00:00:00 2001 From: boyska Date: Sat, 10 Nov 2018 18:00:35 +0100 Subject: [PATCH] HUP on circologd clears the buffer --- cmd/circologd/main.go | 20 +++++++++++++------- hub.go | 9 +++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/cmd/circologd/main.go b/cmd/circologd/main.go index ddde695..d3dfa10 100644 --- a/cmd/circologd/main.go +++ b/cmd/circologd/main.go @@ -31,7 +31,7 @@ func main() { flag.Parse() interrupt := make(chan os.Signal, 1) - signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM) + signal.Notify(interrupt, syscall.SIGINT, syscall.SIGHUP, syscall.SIGTERM) hub := circolog.NewHub(*bufsize) handler := syslog.NewChannelHandler(hub.LogMessages) @@ -84,16 +84,22 @@ func main() { } }() } - + // TODO: now we are ready for { select { case sig := <-interrupt: - log.Println("Quitting because of signal", sig) - server.Kill() - if err := httpServer.Close(); err != nil { - fmt.Fprintln(os.Stderr, "Error closing http server:", err) + if sig == syscall.SIGHUP { + log.Println("Clearing queue") + hub.Clear() + } + if sig == syscall.SIGTERM || sig == syscall.SIGINT { + log.Println("Quitting because of signal", sig) + server.Kill() + if err := httpServer.Close(); err != nil { + fmt.Fprintln(os.Stderr, "Error closing http server:", err) + } + return } - return } } } diff --git a/hub.go b/hub.go index 10bf8c1..eceb3be 100644 --- a/hub.go +++ b/hub.go @@ -101,3 +101,12 @@ func (h *Hub) Run() { } } } + +// Clear removes every all elements from the buffer +func (h *Hub) Clear() { + buf := h.circbuf + for i := 0; i < buf.Len(); i++ { + buf.Value = nil + buf = buf.Next() + } +}