Reorder code

This commit is contained in:
Alex Kotov 2021-08-03 11:25:27 +05:00
parent 7b437a1dcd
commit 17b775b4b9

View file

@ -43,6 +43,32 @@ type node struct {
admin *admin.AdminSocket 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 { func readConfig(log *log.Logger, useconf bool, useconffile string, normaliseconf bool) *config.NodeConfig {
// Use a configuration file. If -useconf, the configuration will be read // Use a configuration file. If -useconf, the configuration will be read
// from stdin. If -useconffile, the configuration will be read from the // from stdin. If -useconffile, the configuration will be read from the
@ -340,29 +366,3 @@ func (n *node) shutdown() {
_ = n.tuntap.Stop() _ = n.tuntap.Stop()
n.core.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
}
}
}