Black Lives Matter. Support the Equal Justice Initiative.

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 aix darwin dragonfly freebsd js,wasm linux 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  
    30  	watchSignalLoop = loop
    31  }
    32  
    33  const (
    34  	numSig = 65 // max across all systems
    35  )
    36  
    37  func signum(sig os.Signal) int {
    38  	switch sig := sig.(type) {
    39  	case syscall.Signal:
    40  		i := int(sig)
    41  		if i < 0 || i >= numSig {
    42  			return -1
    43  		}
    44  		return i
    45  	default:
    46  		return -1
    47  	}
    48  }
    49  
    50  func enableSignal(sig int) {
    51  	signal_enable(uint32(sig))
    52  }
    53  
    54  func disableSignal(sig int) {
    55  	signal_disable(uint32(sig))
    56  }
    57  
    58  func ignoreSignal(sig int) {
    59  	signal_ignore(uint32(sig))
    60  }
    61  
    62  func signalIgnored(sig int) bool {
    63  	return signal_ignored(uint32(sig))
    64  }
    65  

View as plain text