Skip to content

Commit

Permalink
fix linux: undefined: syscall.SIGINFO
Browse files Browse the repository at this point in the history
  • Loading branch information
johansundell committed Jan 5, 2016
1 parent 4e4b2b2 commit 613a333
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flow/signal_handling.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !plan9 !windows
// +build darwin freebsd netbsd openbsd, !plan9, !windows, !linux

package flow

Expand Down
34 changes: 34 additions & 0 deletions flow/signal_handling_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// +build linux

package flow

import (
"os"
"os/signal"
"syscall"
)

func OnInterrupt(fn func()) {
// deal with control+c,etc
signalChan := make(chan os.Signal, 1)
// controlling terminal close, daemon not exit
signal.Ignore(syscall.SIGHUP)
signal.Notify(signalChan,
os.Interrupt,
os.Kill,
syscall.SIGALRM,
// syscall.SIGHUP,
// syscall.SIGINFO, this causes windows to fail
syscall.SIGINT,
syscall.SIGTERM,
// syscall.SIGQUIT, // Quit from keyboard, "kill -3"
)
go func() {
for sig := range signalChan {
fn()
if sig != syscall.SIGTERM {
os.Exit(0)
}
}
}()
}

0 comments on commit 613a333

Please sign in to comment.