Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / libgo / go / os / signal / signal.go
blob666c03e73c4ff87b5900353ffd315cbda8d597af
1 // Copyright 2009 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.
5 // Package signal implements operating system-independent signal handling.
6 package signal
8 import (
9 "runtime"
10 "strconv"
13 // A Signal can represent any operating system signal.
14 type Signal interface {
15 String() string
18 type UnixSignal int32
20 func (sig UnixSignal) String() string {
21 s := runtime.Signame(int32(sig))
22 if len(s) > 0 {
23 return s
25 return "Signal " + strconv.Itoa(int(sig))
28 // Incoming is the global signal channel.
29 // All signals received by the program will be delivered to this channel.
30 var Incoming <-chan Signal
32 func process(ch chan<- Signal) {
33 for {
34 var mask uint32 = runtime.Sigrecv()
35 for sig := uint(0); sig < 32; sig++ {
36 if mask&(1<<sig) != 0 {
37 ch <- UnixSignal(sig)
43 func init() {
44 runtime.Siginit()
45 ch := make(chan Signal) // Done here so Incoming can have type <-chan Signal
46 Incoming = ch
47 go process(ch)