mirror of
https://github.com/zhigang1992/cow.git
synced 2026-01-12 22:46:29 +08:00
Fix cross compile for Windows because no SIGUSR1.
This commit is contained in:
24
main.go
24
main.go
@@ -4,7 +4,6 @@ import (
|
||||
// "flag"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
// "runtime/pprof"
|
||||
"sync"
|
||||
@@ -17,29 +16,6 @@ var (
|
||||
relaunch bool
|
||||
)
|
||||
|
||||
func sigHandler() {
|
||||
// TODO On Windows, these signals will not be triggered on closing cmd
|
||||
// window. How to detect this?
|
||||
sigChan := make(chan os.Signal, 1)
|
||||
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1)
|
||||
|
||||
for sig := range sigChan {
|
||||
// May handle other signals in the future.
|
||||
info.Printf("%v caught, exit\n", sig)
|
||||
storeSiteStat(siteStatExit)
|
||||
if sig == syscall.SIGUSR1 {
|
||||
relaunch = true
|
||||
}
|
||||
close(quit)
|
||||
break
|
||||
}
|
||||
/*
|
||||
if *cpuprofile != "" {
|
||||
pprof.StopCPUProfile()
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// This code is from goagain
|
||||
func lookPath() (argv0 string, err error) {
|
||||
argv0, err = exec.LookPath(os.Args[0])
|
||||
|
||||
30
main_unix.go
Normal file
30
main_unix.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// +build darwin freebsd linux netbsd openbsd
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func sigHandler() {
|
||||
sigChan := make(chan os.Signal, 1)
|
||||
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1)
|
||||
|
||||
for sig := range sigChan {
|
||||
// May handle other signals in the future.
|
||||
info.Printf("%v caught, exit\n", sig)
|
||||
storeSiteStat(siteStatExit)
|
||||
if sig == syscall.SIGUSR1 {
|
||||
relaunch = true
|
||||
}
|
||||
close(quit)
|
||||
break
|
||||
}
|
||||
/*
|
||||
if *cpuprofile != "" {
|
||||
pprof.StopCPUProfile()
|
||||
}
|
||||
*/
|
||||
}
|
||||
33
main_windows.go
Normal file
33
main_windows.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func sigHandler() {
|
||||
// TODO On Windows, these signals will not be triggered on closing cmd
|
||||
// window. How to detect this?
|
||||
sigChan := make(chan os.Signal, 1)
|
||||
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
for sig := range sigChan {
|
||||
// May handle other signals in the future.
|
||||
info.Printf("%v caught, exit\n", sig)
|
||||
storeSiteStat(siteStatExit)
|
||||
// Windows has no SIGUSR1 signal, so relaunching is not supported now.
|
||||
/*
|
||||
if sig == syscall.SIGUSR1 {
|
||||
relaunch = true
|
||||
}
|
||||
*/
|
||||
close(quit)
|
||||
break
|
||||
}
|
||||
/*
|
||||
if *cpuprofile != "" {
|
||||
pprof.StopCPUProfile()
|
||||
}
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user