Always trigger event on shutdown
This commit is contained in:
28
core/core.go
28
core/core.go
@@ -2,9 +2,11 @@ package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/safing/portbase/modules"
|
||||
"github.com/safing/portbase/modules/subsystems"
|
||||
"github.com/tevino/abool"
|
||||
|
||||
// module dependencies
|
||||
_ "github.com/safing/portmaster/netenv"
|
||||
@@ -13,8 +15,15 @@ import (
|
||||
_ "github.com/safing/portmaster/updates"
|
||||
)
|
||||
|
||||
const (
|
||||
eventShutdown = "shutdown"
|
||||
eventRestart = "restart"
|
||||
)
|
||||
|
||||
var (
|
||||
module *modules.Module
|
||||
|
||||
restarting = abool.New()
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -27,6 +36,8 @@ func init() {
|
||||
"config:core/",
|
||||
nil,
|
||||
)
|
||||
|
||||
modules.SetGlobalShutdownFn(shutdownHook)
|
||||
}
|
||||
|
||||
func prep() error {
|
||||
@@ -54,3 +65,20 @@ func start() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func registerEvents() {
|
||||
module.RegisterEvent(eventShutdown, true)
|
||||
module.RegisterEvent(eventRestart, true)
|
||||
}
|
||||
|
||||
func shutdownHook() {
|
||||
// Notify everyone of the restart/shutdown.
|
||||
if restarting.IsNotSet() {
|
||||
module.TriggerEvent(eventShutdown, nil)
|
||||
} else {
|
||||
module.TriggerEvent(eventRestart, nil)
|
||||
}
|
||||
|
||||
// Wait a bit for the event to propagate.
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user