tendermint/common/os.go

29 lines
383 B
Go
Raw Normal View History

2015-04-08 11:35:17 -07:00
package common
import (
"fmt"
"os"
"os/signal"
)
func TrapSignal(cb func()) {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, os.Kill)
2015-04-08 11:35:17 -07:00
go func() {
for sig := range c {
fmt.Printf("captured %v, exiting...\n", sig)
if cb != nil {
cb()
}
os.Exit(1)
}
}()
select {}
}
2015-04-15 20:22:03 -07:00
func Exit(s string) {
fmt.Printf(s + "\n")
os.Exit(1)
}