From 442e09acd6320e13f72d375c0989fef9419875d1 Mon Sep 17 00:00:00 2001 From: childe Date: Thu, 21 May 2020 11:05:57 +0800 Subject: [PATCH] windows do not has user1 signal --- gohangout.go | 35 +---------------------------------- signalhandle_darwin.go | 40 ++++++++++++++++++++++++++++++++++++++++ signalhandle_linux.go | 40 ++++++++++++++++++++++++++++++++++++++++ signalhandle_windows.go | 31 +++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 34 deletions(-) create mode 100644 signalhandle_darwin.go create mode 100644 signalhandle_linux.go create mode 100644 signalhandle_windows.go diff --git a/gohangout.go b/gohangout.go index be88ab56..ed31231c 100644 --- a/gohangout.go +++ b/gohangout.go @@ -6,11 +6,9 @@ import ( "net/http" _ "net/http/pprof" "os" - "os/signal" "runtime" "runtime/pprof" "sync" - "syscall" "github.com/childe/gohangout/input" "github.com/childe/gohangout/topology" @@ -158,7 +156,7 @@ func main() { configChannel <- config } - ListenSignal() + listenSignal() } var boxes []*input.InputBox @@ -185,34 +183,3 @@ func StopBoxesBeat() { boxes = make([]*input.InputBox, 0) } - -func ListenSignal() { - c := make(chan os.Signal, 1) - var stop bool - signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1) - - defer glog.Infof("listen signal stop, exit...") - - for sig := range c { - glog.Infof("capture signal: %v", sig) - switch sig { - case syscall.SIGINT, syscall.SIGTERM: - StopBoxesBeat() - close(configChannel) - stop = true - case syscall.SIGUSR1: - // `kill -USR1 pid`也会触发重新加载 - config, err := parseConfig(options.config) - if err != nil { - glog.Errorf("could not parse config:%s", err) - continue - } - glog.Infof("config:\n%s", removeSensitiveInfo(config)) - configChannel <- config - } - - if stop { - break - } - } -} diff --git a/signalhandle_darwin.go b/signalhandle_darwin.go new file mode 100644 index 00000000..ecfe1416 --- /dev/null +++ b/signalhandle_darwin.go @@ -0,0 +1,40 @@ +package main + +import ( + "os" + "os/signal" + "syscall" + + "github.com/golang/glog" +) + +func listenSignal() { + c := make(chan os.Signal, 1) + var stop bool + signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1) + + defer glog.Infof("listen signal stop, exit...") + + for sig := range c { + glog.Infof("capture signal: %v", sig) + switch sig { + case syscall.SIGINT, syscall.SIGTERM: + StopBoxesBeat() + close(configChannel) + stop = true + case syscall.SIGUSR1: + // `kill -USR1 pid`也会触发重新加载 + config, err := parseConfig(options.config) + if err != nil { + glog.Errorf("could not parse config:%s", err) + continue + } + glog.Infof("config:\n%s", removeSensitiveInfo(config)) + configChannel <- config + } + + if stop { + break + } + } +} diff --git a/signalhandle_linux.go b/signalhandle_linux.go new file mode 100644 index 00000000..ecfe1416 --- /dev/null +++ b/signalhandle_linux.go @@ -0,0 +1,40 @@ +package main + +import ( + "os" + "os/signal" + "syscall" + + "github.com/golang/glog" +) + +func listenSignal() { + c := make(chan os.Signal, 1) + var stop bool + signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1) + + defer glog.Infof("listen signal stop, exit...") + + for sig := range c { + glog.Infof("capture signal: %v", sig) + switch sig { + case syscall.SIGINT, syscall.SIGTERM: + StopBoxesBeat() + close(configChannel) + stop = true + case syscall.SIGUSR1: + // `kill -USR1 pid`也会触发重新加载 + config, err := parseConfig(options.config) + if err != nil { + glog.Errorf("could not parse config:%s", err) + continue + } + glog.Infof("config:\n%s", removeSensitiveInfo(config)) + configChannel <- config + } + + if stop { + break + } + } +} diff --git a/signalhandle_windows.go b/signalhandle_windows.go new file mode 100644 index 00000000..f06eacff --- /dev/null +++ b/signalhandle_windows.go @@ -0,0 +1,31 @@ +package main + +import ( + "os" + "os/signal" + "syscall" + + "github.com/golang/glog" +) + +func listenSignal() { + c := make(chan os.Signal, 1) + var stop bool + signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) + + defer glog.Infof("listen signal stop, exit...") + + for sig := range c { + glog.Infof("capture signal: %v", sig) + switch sig { + case syscall.SIGINT, syscall.SIGTERM: + StopBoxesBeat() + close(configChannel) + stop = true + } + + if stop { + break + } + } +}