From fef73763aa25d4fb3784d388b35a879c68223fe4 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 27 Feb 2019 22:49:22 +0000 Subject: [PATCH] lib/atexit: add SIGTERM to signals which run the exit handlers on unix --- lib/atexit/atexit.go | 5 ++--- lib/atexit/atexit_other.go | 9 +++++++++ lib/atexit/atexit_unix.go | 10 ++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 lib/atexit/atexit_other.go create mode 100644 lib/atexit/atexit_unix.go diff --git a/lib/atexit/atexit.go b/lib/atexit/atexit.go index c369eb787..12b48ed86 100644 --- a/lib/atexit/atexit.go +++ b/lib/atexit/atexit.go @@ -31,11 +31,10 @@ func Register(fn func()) FnHandle { fns[&fn] = true fnsMutex.Unlock() - // Run AtExit handlers on SIGINT or SIGTERM so everything gets - // tidied up properly + // Run AtExit handlers on exitSignals so everything gets tidied up properly registerOnce.Do(func() { exitChan = make(chan os.Signal, 1) - signal.Notify(exitChan, os.Interrupt) // syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT + signal.Notify(exitChan, exitSignals...) go func() { sig := <-exitChan if sig == nil { diff --git a/lib/atexit/atexit_other.go b/lib/atexit/atexit_other.go new file mode 100644 index 000000000..15faa7448 --- /dev/null +++ b/lib/atexit/atexit_other.go @@ -0,0 +1,9 @@ +//+build windows plan9 + +package atexit + +import ( + "os" +) + +var exitSignals = []os.Signal{os.Interrupt} diff --git a/lib/atexit/atexit_unix.go b/lib/atexit/atexit_unix.go new file mode 100644 index 000000000..acebfaf1c --- /dev/null +++ b/lib/atexit/atexit_unix.go @@ -0,0 +1,10 @@ +//+build !windows,!plan9 + +package atexit + +import ( + "os" + "syscall" +) + +var exitSignals = []os.Signal{syscall.SIGINT, syscall.SIGTERM} // Not syscall.SIGQUIT as we want the default behaviour