Browse Source

sigusr2 triggering buffer cleanup also via ctrlsock

Blallo 5 years ago
parent
commit
d61ab0638f
1 changed files with 10 additions and 1 deletions
  1. 10 1
      cmd/circologd/main.go

+ 10 - 1
cmd/circologd/main.go

@@ -32,7 +32,7 @@ func main() {
 	flag.Parse()
 
 	interrupt := make(chan os.Signal, 1)
-	signal.Notify(interrupt, syscall.SIGINT, syscall.SIGUSR1, syscall.SIGTERM)
+	signal.Notify(interrupt, syscall.SIGINT, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGTERM)
 
 	hub := circolog.NewHub(*bufsize)
 	handler := syslog.NewChannelHandler(hub.LogMessages)
@@ -115,6 +115,15 @@ func main() {
 					log.Println("paused")
 				}
 			}
+			if sig == syscall.SIGUSR2 {
+				hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandClear}
+				resp := <-hub.Responses
+				if resp.Value.(bool) {
+					log.Println("buffer cleaned")
+				} else {
+					log.Println("buffer NOT cleaned")
+				}
+			}
 			if sig == syscall.SIGTERM || sig == syscall.SIGINT {
 				log.Println("Quitting because of signal", sig)
 				server.Kill()