Refactor signal handling and remove SPDX licensing details

Redid signal handling in the main server code leading to simpler, more readable code. Removed the SPDX license identifiers from 'go.sum' following recent policy changes.
This commit is contained in:
Winni Neessen 2023-12-15 17:35:27 +01:00
parent ea1ac393bc
commit 436df7b2b4
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D
2 changed files with 21 additions and 28 deletions

View file

@ -45,31 +45,28 @@ func main() {
sc := make(chan os.Signal, 1) sc := make(chan os.Signal, 1)
signal.Notify(sc) signal.Notify(sc)
for { for rc := range sc {
select { if rc == syscall.SIGKILL || rc == syscall.SIGABRT || rc == syscall.SIGINT || rc == syscall.SIGTERM {
case rc := <-sc: l.Warn("received signal. shutting down server", slog.String("signal", rc.String()))
if rc == syscall.SIGKILL || rc == syscall.SIGABRT || rc == syscall.SIGINT || rc == syscall.SIGTERM { // s.Stop()
l.Warn("received signal. shutting down server", slog.String("signal", rc.String())) l.Info("server gracefully shut down")
//s.Stop() os.Exit(0)
l.Info("server gracefully shut down") }
os.Exit(0) if rc == syscall.SIGHUP {
} l.Info(`received "SIGHUP" signal - reloading rules...`)
if rc == syscall.SIGHUP { /*
l.Info(`received "SIGHUP" signal - reloading rules...`) _, nr, err := config.New(config.WithConfFile(*cf), config.WithRulesFile(*rf))
/* if err != nil {
_, nr, err := config.New(config.WithConfFile(*cf), config.WithRulesFile(*rf)) s.Log.Errorf("%s - skipping reload", err)
if err != nil { continue
s.Log.Errorf("%s - skipping reload", err) }
continue if err := nr.CheckRegEx(); err != nil {
} s.Log.Errorf("ruleset validation failed for new ruleset - skipping reload: %s", err)
if err := nr.CheckRegEx(); err != nil { continue
s.Log.Errorf("ruleset validation failed for new ruleset - skipping reload: %s", err) }
continue s.SetRules(nr)
}
s.SetRules(nr)
*/ */
}
} }
} }
} }

4
go.sum
View file

@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2023 Winni Neessen <wn@neessen.dev>
//
// SPDX-License-Identifier: MIT
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=