2012-03-02 16:38:43 +00:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2021-07-30 14:28:58 -07:00
|
|
|
//go:build aix || darwin || dragonfly || freebsd || hurd || (js && wasm) || linux || netbsd || openbsd || solaris || windows
|
2012-03-02 16:38:43 +00:00
|
|
|
|
|
|
|
package signal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
2016-02-03 21:58:02 +00:00
|
|
|
// Defined by the runtime package.
|
2013-07-16 06:54:42 +00:00
|
|
|
func signal_disable(uint32)
|
2012-03-02 16:38:43 +00:00
|
|
|
func signal_enable(uint32)
|
2015-10-31 00:59:47 +00:00
|
|
|
func signal_ignore(uint32)
|
2018-09-24 21:46:21 +00:00
|
|
|
func signal_ignored(uint32) bool
|
2012-03-02 16:38:43 +00:00
|
|
|
func signal_recv() uint32
|
|
|
|
|
|
|
|
func loop() {
|
|
|
|
for {
|
|
|
|
process(syscall.Signal(signal_recv()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2020-01-02 15:05:27 -08:00
|
|
|
watchSignalLoop = loop
|
2012-03-02 16:38:43 +00:00
|
|
|
}
|
|
|
|
|
2013-07-16 06:54:42 +00:00
|
|
|
const (
|
|
|
|
numSig = 65 // max across all systems
|
|
|
|
)
|
|
|
|
|
|
|
|
func signum(sig os.Signal) int {
|
2012-03-02 16:38:43 +00:00
|
|
|
switch sig := sig.(type) {
|
|
|
|
case syscall.Signal:
|
2013-07-16 06:54:42 +00:00
|
|
|
i := int(sig)
|
|
|
|
if i < 0 || i >= numSig {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
return i
|
2012-03-02 16:38:43 +00:00
|
|
|
default:
|
2013-07-16 06:54:42 +00:00
|
|
|
return -1
|
2012-03-02 16:38:43 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-16 06:54:42 +00:00
|
|
|
|
|
|
|
func enableSignal(sig int) {
|
|
|
|
signal_enable(uint32(sig))
|
|
|
|
}
|
|
|
|
|
|
|
|
func disableSignal(sig int) {
|
|
|
|
signal_disable(uint32(sig))
|
|
|
|
}
|
2015-10-31 00:59:47 +00:00
|
|
|
|
|
|
|
func ignoreSignal(sig int) {
|
|
|
|
signal_ignore(uint32(sig))
|
|
|
|
}
|
2018-09-24 21:46:21 +00:00
|
|
|
|
|
|
|
func signalIgnored(sig int) bool {
|
|
|
|
return signal_ignored(uint32(sig))
|
|
|
|
}
|