cli: Backtrace on SIGUSR1

Rework the signal handling code so that if debug is enabled and a
`SIGUSR1` signal is received, backtrace to the system log but continue
to run.

Added some basic tests for the signal handling code.

Fixes #241.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
James O. D. Hunt
2018-04-23 15:23:30 +01:00
parent fc8d913713
commit 6191ddffb3
4 changed files with 166 additions and 9 deletions

View File

@@ -14,8 +14,10 @@ import (
"syscall"
)
// List of fatal signals
var sigFatal = map[syscall.Signal]bool{
// List of handled signals.
//
// The value is true if receiving the signal should be fatal.
var handledSignalsMap = map[syscall.Signal]bool{
syscall.SIGABRT: true,
syscall.SIGBUS: true,
syscall.SIGILL: true,
@@ -24,6 +26,7 @@ var sigFatal = map[syscall.Signal]bool{
syscall.SIGSTKFLT: true,
syscall.SIGSYS: true,
syscall.SIGTRAP: true,
syscall.SIGUSR1: false,
}
func handlePanic() {
@@ -54,13 +57,27 @@ func backtrace() {
}
func fatalSignal(sig syscall.Signal) bool {
return sigFatal[sig]
s, exists := handledSignalsMap[sig]
if !exists {
return false
}
return s
}
func fatalSignals() []syscall.Signal {
func nonFatalSignal(sig syscall.Signal) bool {
s, exists := handledSignalsMap[sig]
if !exists {
return false
}
return !s
}
func handledSignals() []syscall.Signal {
var signals []syscall.Signal
for sig := range sigFatal {
for sig := range handledSignalsMap {
signals = append(signals, sig)
}