forked from chrislusf/glow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix linux: undefined: syscall.SIGINFO
- Loading branch information
1 parent
4e4b2b2
commit 613a333
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
}() | ||
} |