os/signal: add ability to ignore signals and restore initial signal handlers

There is currently no way to ignore signals using the os/signal package.
It is possible to catch a signal and do nothing but this is not the same
as ignoring it. The new function Ignore allows a set of signals to be
ignored. The new function Reset allows the initial handlers for a set of
signals to be restored.

Fixes #5572

Change-Id: I5c0f07956971e3a9ff9b9d9631e6e3a08c20df15
Reviewed-on: https://go-review.googlesource.com/3580
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Michael MacInnis 2015-01-29 22:37:41 -05:00 committed by Ian Lance Taylor
parent 10a4696fb8
commit 194ad16b83
12 changed files with 169 additions and 2 deletions

View file

@ -153,6 +153,15 @@ func signal_disable(s uint32) {
sigdisable(s)
}
// Must only be called from a single goroutine at a time.
func signal_ignore(s uint32) {
if int(s) >= len(sig.wanted)*32 {
return
}
sig.wanted[s/32] &^= 1 << (s & 31)
sigignore(s)
}
// This runs on a foreign stack, without an m or a g. No stack split.
//go:nosplit
func badsignal(sig uintptr) {