From dfb1b696656bd56e10c3085e145fe5f40dc2ba42 Mon Sep 17 00:00:00 2001 From: Adam Azarchs Date: Thu, 19 Apr 2018 19:59:39 -0700 Subject: os/signal: add func Ignored(sig Signal) bool Ignored reports whether sig is currently ignored. This implementation only works applies on Unix systems for now. However, at the moment that is also the case for Ignore() and several other signal interaction methods, so that seems fair. Fixes #22497 Change-Id: I7c1b1a5e12373ca5da44709500ff5acedc6f1316 Reviewed-on: https://go-review.googlesource.com/108376 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/signal_unix.go | 2 ++ src/runtime/sigqueue.go | 9 +++++++++ src/runtime/sigqueue_plan9.go | 5 +++++ 3 files changed, 16 insertions(+) (limited to 'src/runtime') diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go index d87f1bed16..0d8caae7a0 100644 --- a/src/runtime/signal_unix.go +++ b/src/runtime/signal_unix.go @@ -103,6 +103,8 @@ func initsig(preinit bool) { // set SA_ONSTACK if necessary. if fwdSig[i] != _SIG_DFL && fwdSig[i] != _SIG_IGN { setsigstack(i) + } else if fwdSig[i] == _SIG_IGN { + sigInitIgnored(i) } continue } diff --git a/src/runtime/sigqueue.go b/src/runtime/sigqueue.go index 98331627eb..9f53240954 100644 --- a/src/runtime/sigqueue.go +++ b/src/runtime/sigqueue.go @@ -237,7 +237,16 @@ func signal_ignore(s uint32) { atomic.Store(&sig.ignored[s/32], i) } +// sigInitIgnored marks the signal as already ignored. This is called at +// program start by siginit. +func sigInitIgnored(s uint32) { + i := sig.ignored[s/32] + i |= 1 << (s & 31) + atomic.Store(&sig.ignored[s/32], i) +} + // Checked by signal handlers. +//go:linkname signal_ignored os/signal.signal_ignored func signal_ignored(s uint32) bool { i := atomic.Load(&sig.ignored[s/32]) return i&(1<<(s&31)) != 0 diff --git a/src/runtime/sigqueue_plan9.go b/src/runtime/sigqueue_plan9.go index 76668045a8..934742a1f4 100644 --- a/src/runtime/sigqueue_plan9.go +++ b/src/runtime/sigqueue_plan9.go @@ -152,3 +152,8 @@ func signal_disable(s uint32) { //go:linkname signal_ignore os/signal.signal_ignore func signal_ignore(s uint32) { } + +//go:linkname signal_ignored os/signal.signal_ignored +func signal_ignored(s uint32) bool { + return false +} -- cgit v1.3-5-g9baa