github.com/zxy12/go_duplicate_112_new@v0.0.0-20200807091221-747231827200/src/os/signal/signal_unix.go (about) 1 // Copyright 2012 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris windows 6 7 package signal 8 9 import ( 10 "os" 11 "syscall" 12 ) 13 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 func signal_recv() uint32 20 21 func loop() { 22 for { 23 process(syscall.Signal(signal_recv())) 24 } 25 } 26 27 func init() { 28 signal_enable(0) // first call - initialize 29 go loop() 30 } 31 32 const ( 33 numSig = 65 // max across all systems 34 ) 35 36 func signum(sig os.Signal) int { 37 switch sig := sig.(type) { 38 case syscall.Signal: 39 i := int(sig) 40 if i < 0 || i >= numSig { 41 return -1 42 } 43 return i 44 default: 45 return -1 46 } 47 } 48 49 func enableSignal(sig int) { 50 signal_enable(uint32(sig)) 51 } 52 53 func disableSignal(sig int) { 54 signal_disable(uint32(sig)) 55 } 56 57 func ignoreSignal(sig int) { 58 signal_ignore(uint32(sig)) 59 } 60 61 func signalIgnored(sig int) bool { 62 return signal_ignored(uint32(sig)) 63 }