From 17b775b4b9e9b09e9f698e07328a76b9c1b452c1 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Tue, 3 Aug 2021 11:25:27 +0500 Subject: [PATCH] Reorder code --- cmd/yggdrasil/main.go | 52 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/cmd/yggdrasil/main.go b/cmd/yggdrasil/main.go index 2f2a9bb6..172beb17 100644 --- a/cmd/yggdrasil/main.go +++ b/cmd/yggdrasil/main.go @@ -43,6 +43,32 @@ type node struct { admin *admin.AdminSocket } +func main() { + var cmdLineEnv CmdLineEnv + cmdLineEnv.parseFlagsAndArgs() + + hup := make(chan os.Signal, 1) + //signal.Notify(hup, os.Interrupt, syscall.SIGHUP) + term := make(chan os.Signal, 1) + signal.Notify(term, os.Interrupt, syscall.SIGTERM) + for { + done := make(chan struct{}) + ctx, cancel := context.WithCancel(context.Background()) + go run(cmdLineEnv, ctx, done) + select { + case <-hup: + cancel() + <-done + case <-term: + cancel() + <-done + return + case <-done: + return + } + } +} + func readConfig(log *log.Logger, useconf bool, useconffile string, normaliseconf bool) *config.NodeConfig { // Use a configuration file. If -useconf, the configuration will be read // from stdin. If -useconffile, the configuration will be read from the @@ -340,29 +366,3 @@ func (n *node) shutdown() { _ = n.tuntap.Stop() n.core.Stop() } - -func main() { - var cmdLineEnv CmdLineEnv - cmdLineEnv.parseFlagsAndArgs() - - hup := make(chan os.Signal, 1) - //signal.Notify(hup, os.Interrupt, syscall.SIGHUP) - term := make(chan os.Signal, 1) - signal.Notify(term, os.Interrupt, syscall.SIGTERM) - for { - done := make(chan struct{}) - ctx, cancel := context.WithCancel(context.Background()) - go run(cmdLineEnv, ctx, done) - select { - case <-hup: - cancel() - <-done - case <-term: - cancel() - <-done - return - case <-done: - return - } - } -}