From be54136c5c3e326bddda807305978af5757681b1 Mon Sep 17 00:00:00 2001 From: Mantas Vidutis Date: Tue, 23 Apr 2019 16:01:20 -0700 Subject: [PATCH] move signal handler to other handlers --- p2pd/main.go | 9 --------- trap_posix.go | 11 ++++++++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/p2pd/main.go b/p2pd/main.go index 38f29a5..87365d7 100644 --- a/p2pd/main.go +++ b/p2pd/main.go @@ -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. diff --git a/trap_posix.go b/trap_posix.go index 003cb0d..258ac22 100644 --- a/trap_posix.go +++ b/trap_posix.go @@ -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) }