commit 2e55e2f8444fafd5e86d8fd18db619f706f97808
parent 5cf5c48fd635559a2f65af47a1ca7c5e201469a0
Author: Robert Russell <robertrussell.72001@gmail.com>
Date: Tue, 16 Jul 2024 17:26:34 -0700
Simplify exit signal handling
Diffstat:
| M | tlsrp.go | | | 27 | +++++++-------------------- |
1 file changed, 7 insertions(+), 20 deletions(-)
diff --git a/tlsrp.go b/tlsrp.go
@@ -273,30 +273,17 @@ func manageConfig(cfgPath string) {
}
}
-// TODO: Simplify this so all signals soft exit first, then hard exit second
func manageExit() {
sigs := make(chan os.Signal, 3)
signal.Notify(sigs, unix.SIGINT, unix.SIGQUIT, unix.SIGTERM)
- softExiting := false
- for sig := range sigs {
- switch sig {
- case unix.SIGINT, unix.SIGQUIT:
- if !softExiting {
- log.Println("received SIGINT/SIGQUIT; exiting softly")
- close(softExit)
- softExiting = true
- } else {
- log.Println("received another SIGINT/SIGQUIT; exiting harshly")
- close(hardExit)
- return
- }
- case unix.SIGTERM:
- log.Println("received SIGTERM; exiting harshly")
- close(hardExit)
- return
- }
- }
+ <-sigs
+ log.Println("received SIGINT/SIGQUIT/SIGTERM; exiting softly")
+ close(softExit)
+
+ <-sigs
+ log.Println("received another SIGINT/SIGQUIT/SIGTERM; exiting harshly")
+ close(hardExit)
}
func main() {