mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	More directly define a minwinsvc exit handler
This commit is contained in:
		
							parent
							
								
									12486b0557
								
							
						
					
					
						commit
						02c99d3e7d
					
				
					 1 changed files with 11 additions and 12 deletions
				
			
		| 
						 | 
					@ -172,7 +172,7 @@ func main() {
 | 
				
			||||||
			logger = log.New(syslogger, "", log.Flags())
 | 
								logger = log.New(syslogger, "", log.Flags())
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	default:
 | 
						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())
 | 
								logger = log.New(logfd, "", log.Flags())
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -242,11 +242,16 @@ func main() {
 | 
				
			||||||
	r := make(chan os.Signal, 1)
 | 
						r := make(chan os.Signal, 1)
 | 
				
			||||||
	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
 | 
						signal.Notify(c, os.Interrupt, syscall.SIGTERM)
 | 
				
			||||||
	signal.Notify(r, os.Interrupt, syscall.SIGHUP)
 | 
						signal.Notify(r, os.Interrupt, syscall.SIGHUP)
 | 
				
			||||||
	// Create a function to capture the service being stopped on Windows.
 | 
						// Define what happens when we want to stop Yggdrasil.
 | 
				
			||||||
	winTerminate := func() {
 | 
						terminate := func() {
 | 
				
			||||||
		c <- os.Interrupt
 | 
							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
 | 
						// Wait for the terminate/interrupt signal. Once a signal is received, the
 | 
				
			||||||
	// deferred Stop function above will run which will shut down TUN/TAP.
 | 
						// deferred Stop function above will run which will shut down TUN/TAP.
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
| 
						 | 
					@ -265,13 +270,7 @@ func main() {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
exit:
 | 
					exit:
 | 
				
			||||||
	// When gracefully shutting down we should try and clean up as much as
 | 
						terminate()
 | 
				
			||||||
	// possible, although not all of these functions are necessarily implemented
 | 
					 | 
				
			||||||
	// yet
 | 
					 | 
				
			||||||
	n.core.Stop()
 | 
					 | 
				
			||||||
	n.admin.Stop()
 | 
					 | 
				
			||||||
	n.multicast.Stop()
 | 
					 | 
				
			||||||
	n.tuntap.Stop()
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (n *node) sessionFirewall(pubkey *crypto.BoxPubKey, initiator bool) bool {
 | 
					func (n *node) sessionFirewall(pubkey *crypto.BoxPubKey, initiator bool) bool {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue