move signal handler to other handlers

This commit is contained in:
Mantas Vidutis 2019-04-23 16:01:20 -07:00
parent c45551178a
commit be54136c5c
2 changed files with 10 additions and 10 deletions

View File

@ -306,15 +306,6 @@ func main() {
log.Fatal(err)
}
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt)
go func() {
for _ = range sigChan {
d.Close()
os.Exit(int(syscall.SIGINT))
}
}()
if c.AutoNat {
var opts []libp2p.Option
// allow the AutoNAT service to dial back quic addrs.

View File

@ -11,13 +11,22 @@ import (
func (d *Daemon) trapSignals() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGUSR1)
signal.Notify(ch, syscall.SIGUSR1, syscall.SIGINT, syscall.SIGTERM, syscall.SIGABRT)
for {
select {
case s := <-ch:
switch s {
case syscall.SIGUSR1:
d.handleSIGUSR1()
case syscall.SIGINT:
d.Close()
os.Exit(int(syscall.SIGINT))
case syscall.SIGTERM:
d.Close()
os.Exit(int(syscall.SIGTERM))
case syscall.SIGABRT:
d.Close()
os.Exit(int(syscall.SIGABRT))
default:
log.Warningf("unexpected signal %d", s)
}