...
Run Format

Source file src/os/signal/signal_unix.go

Documentation: os/signal

     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  // Defined by the runtime package.
    15  func signal_disable(uint32)
    16  func signal_enable(uint32)
    17  func signal_ignore(uint32)
    18  func signal_recv() uint32
    19  
    20  func loop() {
    21  	for {
    22  		process(syscall.Signal(signal_recv()))
    23  	}
    24  }
    25  
    26  func init() {
    27  	signal_enable(0) // first call - initialize
    28  	go loop()
    29  }
    30  
    31  const (
    32  	numSig = 65 // max across all systems
    33  )
    34  
    35  func signum(sig os.Signal) int {
    36  	switch sig := sig.(type) {
    37  	case syscall.Signal:
    38  		i := int(sig)
    39  		if i < 0 || i >= numSig {
    40  			return -1
    41  		}
    42  		return i
    43  	default:
    44  		return -1
    45  	}
    46  }
    47  
    48  func enableSignal(sig int) {
    49  	signal_enable(uint32(sig))
    50  }
    51  
    52  func disableSignal(sig int) {
    53  	signal_disable(uint32(sig))
    54  }
    55  
    56  func ignoreSignal(sig int) {
    57  	signal_ignore(uint32(sig))
    58  }
    59  

View as plain text