From 02c99d3e7d2ae9d66557533e365ecc5f79113ebe Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 6 Jul 2019 12:04:31 +0100 Subject: [PATCH] More directly define a minwinsvc exit handler --- cmd/yggdrasil/main.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/cmd/yggdrasil/main.go b/cmd/yggdrasil/main.go index fd8828c..7944684 100644 --- a/cmd/yggdrasil/main.go +++ b/cmd/yggdrasil/main.go @@ -172,7 +172,7 @@ func main() { logger = log.New(syslogger, "", log.Flags()) } default: - if logfd, err := os.Create(*logto); err == nil { + if logfd, err := os.OpenFile(*logto, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644); err == nil { logger = log.New(logfd, "", log.Flags()) } } @@ -242,11 +242,16 @@ func main() { r := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM) signal.Notify(r, os.Interrupt, syscall.SIGHUP) - // Create a function to capture the service being stopped on Windows. - winTerminate := func() { - c <- os.Interrupt + // Define what happens when we want to stop Yggdrasil. + terminate := func() { + n.core.Stop() + n.admin.Stop() + n.multicast.Stop() + n.tuntap.Stop() + os.Exit(0) } - minwinsvc.SetOnExit(winTerminate) + // Capture the service being stopped on Windows. + minwinsvc.SetOnExit(terminate) // Wait for the terminate/interrupt signal. Once a signal is received, the // deferred Stop function above will run which will shut down TUN/TAP. for { @@ -265,13 +270,7 @@ func main() { } } exit: - // When gracefully shutting down we should try and clean up as much as - // possible, although not all of these functions are necessarily implemented - // yet - n.core.Stop() - n.admin.Stop() - n.multicast.Stop() - n.tuntap.Stop() + terminate() } func (n *node) sessionFirewall(pubkey *crypto.BoxPubKey, initiator bool) bool {