github.com/tcnksm/go@v0.0.0-20141208075154-439b32936367/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 darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows
     6  
     7  package signal
     8  
     9  import (
    10  	"os"
    11  	"syscall"
    12  )
    13  
    14  // In assembly.
    15  func signal_disable(uint32)
    16  func signal_enable(uint32)
    17  func signal_recv() uint32
    18  
    19  func loop() {
    20  	for {
    21  		process(syscall.Signal(signal_recv()))
    22  	}
    23  }
    24  
    25  func init() {
    26  	signal_enable(0) // first call - initialize
    27  	go loop()
    28  }
    29  
    30  const (
    31  	numSig = 65 // max across all systems
    32  )
    33  
    34  func signum(sig os.Signal) int {
    35  	switch sig := sig.(type) {
    36  	case syscall.Signal:
    37  		i := int(sig)
    38  		if i < 0 || i >= numSig {
    39  			return -1
    40  		}
    41  		return i
    42  	default:
    43  		return -1
    44  	}
    45  }
    46  
    47  func enableSignal(sig int) {
    48  	signal_enable(uint32(sig))
    49  }
    50  
    51  func disableSignal(sig int) {
    52  	signal_disable(uint32(sig))
    53  }