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) 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 { if c.AutoNat {
var opts []libp2p.Option var opts []libp2p.Option
// allow the AutoNAT service to dial back quic addrs. // allow the AutoNAT service to dial back quic addrs.

View File

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