...
Run Format

Source file src/os/signal/signal_plan9.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  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_ignored(uint32) bool
    19  func signal_recv() string
    20  
    21  func init() {
    22  	signal_enable(0) // first call - initialize
    23  	go loop()
    24  }
    25  
    26  func loop() {
    27  	for {
    28  		process(syscall.Note(signal_recv()))
    29  	}
    30  }
    31  
    32  const numSig = 256
    33  
    34  func signum(sig os.Signal) int {
    35  	switch sig := sig.(type) {
    36  	case syscall.Note:
    37  		n, ok := sigtab[sig]
    38  		if !ok {
    39  			n = len(sigtab) + 1
    40  			if n > numSig {
    41  				return -1
    42  			}
    43  			sigtab[sig] = n
    44  		}
    45  		return n
    46  	default:
    47  		return -1
    48  	}
    49  }
    50  
    51  func enableSignal(sig int) {
    52  	signal_enable(uint32(sig))
    53  }
    54  
    55  func disableSignal(sig int) {
    56  	signal_disable(uint32(sig))
    57  }
    58  
    59  func ignoreSignal(sig int) {
    60  	signal_ignore(uint32(sig))
    61  }
    62  
    63  func signalIgnored(sig int) bool {
    64  	return signal_ignored(uint32(sig))
    65  }
    66  

View as plain text