MCPcopy Index your code
hub / github.com/foxcpp/maddy / handleSignals

Function handleSignals

signal.go:39–65  ·  view source on GitHub ↗

handleSignals function creates and listens on OS signals channel. OS-specific signals that correspond to the program termination (SIGTERM, SIGHUP, SIGINT) will cause this function to return. SIGUSR1 will call reinitLogging without returning.

()

Source from the content-addressed store, hash-verified

37//
38// SIGUSR1 will call reinitLogging without returning.
39func handleSignals() (reload bool) {
40 sig := make(chan os.Signal, 5)
41 signal.Notify(sig, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT, syscall.SIGUSR1, syscall.SIGUSR2)
42 defer signal.Stop(sig)
43
44 for {
45 switch s := <-sig; s {
46 case syscall.SIGUSR1:
47 log.Printf("signal received (%s), rotating logs", s.String())
48 systemdStatus(SDReloading, "Reopening logs...")
49 hooks.RunHooks(hooks.EventLogRotate)
50 systemdStatus(SDReady, "Listening for incoming connections...")
51 case syscall.SIGUSR2:
52 log.Printf("signal received (%s), reloading configuration", s.String())
53 return true
54 default:
55 go func() {
56 s := handleSignals()
57 log.Printf("forced shutdown due to signal (%v)!", s)
58 os.Exit(1)
59 }()
60
61 log.Printf("signal received (%v), next signal will force immediate shutdown.", s)
62 return false
63 }
64 }
65}

Callers 1

moduleMainFunction · 0.70

Calls 5

PrintfFunction · 0.92
RunHooksFunction · 0.92
systemdStatusFunction · 0.70
StopMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected