Commit 6c921116 authored by Cameron Currie's avatar Cameron Currie

Exclude some signals/syscall code on Windows

parent 4108c5e2
......@@ -8,11 +8,11 @@ func main() {
go WatchSignals(finished)
RegisterEventHandler("sigint",func(){
fmt.Prinln("got signint")
fmt.Prinln("got signint")
})
// block here, should put this goroutine into sleep mode
v := <-finished
v := <-finished
}
*/
......@@ -21,9 +21,7 @@ package gou
import (
"os"
"os/signal"
"sync"
"syscall"
"time"
)
......@@ -33,7 +31,7 @@ var (
)
// Wait for condition (defined by func) to be true
// this is mostly for testing, but a utility to
// this is mostly for testing, but a utility to
// create a ticker checking back every 100 ms to see
// if something (the supplied check func) is done
//
......@@ -57,64 +55,6 @@ func WaitFor(check func() bool, timeoutSecs int) {
}
}
// a watcher that tries to trap sys signals so you can gracefully shutdown.
// Make sure to only call this once. Currently monitors events [sigterm,
// sigint, sigabrt,sigquit,sigstop, sigusr1,sigusr2]
func WatchSignals(quit chan bool) {
var sig os.Signal
sigIn := make(chan os.Signal, 1)
signal.Notify(sigIn)
defer func() {
if r := recover(); r != nil {
Debug("Recovered in Watch Signals", r)
}
}()
for {
sig = <-sigIn
if sig.(os.Signal) == syscall.SIGTERM {
Log(DEBUG, "in WatchSignal Handle Sig term")
RunEventHandlers("sigterm")
RunEventHandlers("onexit")
quit <- true
}
if sig.(os.Signal) == syscall.SIGINT {
Log(DEBUG, "in WatchSignal Handle Sig Int")
RunEventHandlers("sigint")
RunEventHandlers("onexit")
quit <- true
}
if sig.(os.Signal) == syscall.SIGABRT {
Log(DEBUG, "in WatchSignal Handle SIGABRT")
RunEventHandlers("sigabrt")
RunEventHandlers("onexit")
quit <- true
//os.Exit(9)
}
if sig.(os.Signal) == syscall.SIGQUIT {
Log(DEBUG, "in WatchSignal Handle SIGQUIT")
RunEventHandlers("sigquit")
RunEventHandlers("onexit")
quit <- true
}
if sig.(os.Signal) == syscall.SIGSTOP {
Log(DEBUG, "in WatchSignal Handle SIGSTOP")
RunEventHandlers("SIGSTOP")
}
if sig.(os.Signal) == syscall.SIGUSR1 {
Log(DEBUG, "in WatchSignal Handle SIGUSR1")
RunEventHandlers("SIGUSR1")
}
if sig.(os.Signal) == syscall.SIGUSR2 {
Log(DEBUG, "in WatchSignal Handle SIGUSR2")
RunEventHandlers("SIGUSR2")
}
Debug(sig)
}
}
// Call to execute event handlers registered earlier
func RunEventHandlers(event string) {
eventsMu.Lock()
......
// +build !windows
package gou
import (
"os"
"os/signal"
"syscall"
)
// a watcher that tries to trap sys signals so you can gracefully shutdown.
// Make sure to only call this once. Currently monitors events [sigterm,
// sigint, sigabrt,sigquit,sigstop, sigusr1,sigusr2]
func WatchSignals(quit chan bool) {
var sig os.Signal
sigIn := make(chan os.Signal, 1)
signal.Notify(sigIn)
defer func() {
if r := recover(); r != nil {
Debug("Recovered in Watch Signals", r)
}
}()
for {
sig = <-sigIn
if sig.(os.Signal) == syscall.SIGTERM {
Log(DEBUG, "in WatchSignal Handle Sig term")
RunEventHandlers("sigterm")
RunEventHandlers("onexit")
quit <- true
}
if sig.(os.Signal) == syscall.SIGINT {
Log(DEBUG, "in WatchSignal Handle Sig Int")
RunEventHandlers("sigint")
RunEventHandlers("onexit")
quit <- true
}
if sig.(os.Signal) == syscall.SIGABRT {
Log(DEBUG, "in WatchSignal Handle SIGABRT")
RunEventHandlers("sigabrt")
RunEventHandlers("onexit")
quit <- true
//os.Exit(9)
}
if sig.(os.Signal) == syscall.SIGQUIT {
Log(DEBUG, "in WatchSignal Handle SIGQUIT")
RunEventHandlers("sigquit")
RunEventHandlers("onexit")
quit <- true
}
if sig.(os.Signal) == syscall.SIGSTOP {
Log(DEBUG, "in WatchSignal Handle SIGSTOP")
RunEventHandlers("SIGSTOP")
}
if sig.(os.Signal) == syscall.SIGUSR1 {
Log(DEBUG, "in WatchSignal Handle SIGUSR1")
RunEventHandlers("SIGUSR1")
}
if sig.(os.Signal) == syscall.SIGUSR2 {
Log(DEBUG, "in WatchSignal Handle SIGUSR2")
RunEventHandlers("SIGUSR2")
}
Debug(sig)
}
}
// +build windows
package gou
import (
"os"
"os/signal"
"syscall"
)
// a watcher that tries to trap sys signals so you can gracefully shutdown.
// Make sure to only call this once. Currently monitors events [sigterm,
// sigint, sigabrt,sigquit,sigstop, sigusr1,sigusr2]
func WatchSignals(quit chan bool) {
var sig os.Signal
sigIn := make(chan os.Signal, 1)
signal.Notify(sigIn)
defer func() {
if r := recover(); r != nil {
Debug("Recovered in Watch Signals", r)
}
}()
for {
sig = <-sigIn
if sig.(os.Signal) == syscall.SIGTERM {
Log(DEBUG, "in WatchSignal Handle Sig term")
RunEventHandlers("sigterm")
RunEventHandlers("onexit")
quit <- true
}
if sig.(os.Signal) == syscall.SIGINT {
Log(DEBUG, "in WatchSignal Handle Sig Int")
RunEventHandlers("sigint")
RunEventHandlers("onexit")
quit <- true
}
if sig.(os.Signal) == syscall.SIGABRT {
Log(DEBUG, "in WatchSignal Handle SIGABRT")
RunEventHandlers("sigabrt")
RunEventHandlers("onexit")
quit <- true
//os.Exit(9)
}
if sig.(os.Signal) == syscall.SIGQUIT {
Log(DEBUG, "in WatchSignal Handle SIGQUIT")
RunEventHandlers("sigquit")
RunEventHandlers("onexit")
quit <- true
}
Debug(sig)
}
}
......@@ -5,8 +5,6 @@ import (
"log"
"os"
"strings"
"syscall"
"unsafe"
)
const (
......@@ -243,24 +241,3 @@ type winsize struct {
const (
_TIOCGWINSZ = 0x5413 // OSX 1074295912
)
// Determine is this process is running in a Terminal or not?
func IsTerminal() bool {
ws := &winsize{}
isTerm := true
defer func() {
if r := recover(); r != nil {
isTerm = false
}
}()
// This blows up on windows
retCode, _, _ := syscall.Syscall(syscall.SYS_IOCTL,
uintptr(syscall.Stdin),
uintptr(_TIOCGWINSZ),
uintptr(unsafe.Pointer(ws)))
if int(retCode) == -1 {
return false
}
return isTerm
}
// +build !windows
package gou
// Determine is this process is running in a Terminal or not?
func IsTerminal() bool {
ws := &winsize{}
isTerm := true
defer func() {
if r := recover(); r != nil {
isTerm = false
}
}()
// This blows up on windows
retCode, _, _ := syscall.Syscall(syscall.SYS_IOCTL,
uintptr(syscall.Stdin),
uintptr(_TIOCGWINSZ),
uintptr(unsafe.Pointer(ws)))
if int(retCode) == -1 {
return false
}
return isTerm
}
// +build windows
package gou
// Determine is this process is running in a Terminal or not?
func IsTerminal() bool {
return false // TODO Needs correct implementation on Windows
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment