github.com/FenixAra/go@v0.0.0-20170127160404-96ea0918e670/src/os/signal/signal_plan9.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  package signal
     6  
     7  import (
     8  	"os"
     9  	"syscall"
    10  )
    11  
    12  var sigtab = make(map[os.Signal]int)
    13  
    14  // In sig.s; jumps to runtime.
    15  func signal_disable(uint32)
    16  func signal_enable(uint32)
    17  func signal_ignore(uint32)
    18  func signal_recv() string
    19  
    20  func init() {
    21  	signal_enable(0) // first call - initialize
    22  	go loop()
    23  }
    24  
    25  func loop() {
    26  	for {
    27  		process(syscall.Note(signal_recv()))
    28  	}
    29  }
    30  
    31  const numSig = 256
    32  
    33  func signum(sig os.Signal) int {
    34  	switch sig := sig.(type) {
    35  	case syscall.Note:
    36  		n, ok := sigtab[sig]
    37  		if !ok {
    38  			n = len(sigtab) + 1
    39  			if n > numSig {
    40  				return -1
    41  			}
    42  			sigtab[sig] = n
    43  		}
    44  		return n
    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  }