...

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  //go:build aix || darwin || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris || windows
		 6  // +build aix darwin dragonfly freebsd js,wasm linux netbsd openbsd solaris windows
		 7  
		 8  package signal
		 9  
		10  import (
		11  	"os"
		12  	"syscall"
		13  )
		14  
		15  // Defined by the runtime package.
		16  func signal_disable(uint32)
		17  func signal_enable(uint32)
		18  func signal_ignore(uint32)
		19  func signal_ignored(uint32) bool
		20  func signal_recv() uint32
		21  
		22  func loop() {
		23  	for {
		24  		process(syscall.Signal(signal_recv()))
		25  	}
		26  }
		27  
		28  func init() {
		29  	watchSignalLoop = 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  }
		64  

View as plain text