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  	watchSignalLoop = 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  
    60  func signalIgnored(sig int) bool {
    61  	return signal_ignored(uint32(sig))
    62  }
    63  

View as plain text