func handleSignals(sigchans []chan os.Signal, handler func(linux.Signal), stop, done chan struct{}) {
	// Build a select case.
	sc := []reflect.SelectCase{{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(stop)}}
	for _, sigchan := range sigchans {
		sc = append(sc, reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(sigchan)})
	}

	for {
		// Wait for a notification.
		index, _, ok := reflect.Select(sc)

		// Was it the stop channel?
		if index == 0 {
			if !ok {
				// Stop forwarding and notify that it's done.
				close(done)
				return
			}
			continue
		}

		// How about a different close?
		if !ok {
			panic("signal channel closed unexpectedly")
		}

		// Otherwise, it was a signal on channel N. Index 0 represents the stop
		// channel, so index N represents the channel for signal N.
		handler(linux.Signal(index))
	}
}
// handleSignals listens for incoming signals and calls the given handler
// function.
//
// It stops when the stop channel is closed. The done channel is closed once it
// will no longer deliver signals to k.
handleSignals listens for incoming signals and calls the given handler
function.

It stops when the stop channel is closed. The done channel is closed once it
will no longer deliver signals to k.
// handleSignals listens for incoming signals and calls the given handler // function . // // It stops when the stop channel is closed . The done channel is closed once it // will no longer deliver signals to k .
func handleSignals(sigchans []chan os.Signal, handler func(linux.Signal), stop, done chan struct{}) {
	sc := []reflect.SelectCase{{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(stop)}}
	for _, sigchan := range sigchans {
		sc = append(sc, reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(sigchan)})
	}
	for {
		index, _, ok := reflect.Select(sc)
		if index == 0 {
			if !ok {
				close(done)
				return
			}
			continue
		}
		if !ok {
			panic("signal channel closed unexpectedly")
		}
		handler(linux.Signal(index))
	}
}
func handleSignals ( sigchans [ ] chan os . Signal , handler func ( linux . Signal ) , stop , done chan struct { } ) { sc := [ ] reflect . SelectCase { { Dir : reflect . SelectRecv , Chan : reflect . ValueOf ( stop ) } } for _ , sigchan := range sigchans { sc = append ( sc , reflect . SelectCase { Dir : reflect . SelectRecv , Chan : reflect . ValueOf ( sigchan ) } ) } for { index , _ , ok := reflect . Select ( sc ) if index == 0 { if ! ok { close ( done ) return } continue } if ! ok { panic ( " " ) } handler ( linux . Signal ( index ) ) } }
handleSignals listens for incoming signals and calls the given handler
function.
handleSignals listens for incoming signals and calls the given handler function .
// Build a select case. // Wait for a notification. // Was it the stop channel? // Stop forwarding and notify that it's done. // How about a different close? // Otherwise, it was a signal on channel N. Index 0 represents the stop // channel, so index N represents the channel for signal N.