signal_unix.go 1.08 KB
Newer Older
1 2 3 4
// 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.

5
// +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris windows
6 7 8 9 10 11 12 13

package signal

import (
	"os"
	"syscall"
)

14
// Defined by the runtime package.
15
func signal_disable(uint32)
16
func signal_enable(uint32)
17
func signal_ignore(uint32)
18
func signal_ignored(uint32) bool
19 20 21 22 23 24 25 26 27 28 29 30 31
func signal_recv() uint32

func loop() {
	for {
		process(syscall.Signal(signal_recv()))
	}
}

func init() {
	signal_enable(0) // first call - initialize
	go loop()
}

32 33 34 35 36
const (
	numSig = 65 // max across all systems
)

func signum(sig os.Signal) int {
37 38
	switch sig := sig.(type) {
	case syscall.Signal:
39 40 41 42 43
		i := int(sig)
		if i < 0 || i >= numSig {
			return -1
		}
		return i
44
	default:
45
		return -1
46 47
	}
}
48 49 50 51 52 53 54 55

func enableSignal(sig int) {
	signal_enable(uint32(sig))
}

func disableSignal(sig int) {
	signal_disable(uint32(sig))
}
56 57 58 59

func ignoreSignal(sig int) {
	signal_ignore(uint32(sig))
}
60 61 62 63

func signalIgnored(sig int) bool {
	return signal_ignored(uint32(sig))
}