2015-07-25 10:35:07 +02:00
|
|
|
// Package signal provides helper functions for dealing with signals across
|
|
|
|
// various operating systems.
|
2014-03-10 13:38:17 -07:00
|
|
|
package signal
|
2013-10-29 11:59:08 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
)
|
|
|
|
|
2015-07-25 10:35:07 +02:00
|
|
|
// CatchAll catches all signals and relays them to the specified channel.
|
2014-03-10 13:50:16 -07:00
|
|
|
func CatchAll(sigc chan os.Signal) {
|
|
|
|
handledSigs := []os.Signal{}
|
2014-03-10 14:22:27 -07:00
|
|
|
for _, s := range SignalMap {
|
2014-03-10 13:50:16 -07:00
|
|
|
handledSigs = append(handledSigs, s)
|
|
|
|
}
|
|
|
|
signal.Notify(sigc, handledSigs...)
|
|
|
|
}
|
|
|
|
|
2015-07-25 10:35:07 +02:00
|
|
|
// StopCatch stops catching the signals and closes the specified channel.
|
2013-10-29 11:59:08 -07:00
|
|
|
func StopCatch(sigc chan os.Signal) {
|
|
|
|
signal.Stop(sigc)
|
|
|
|
close(sigc)
|
|
|
|
}
|