diff --git a/Makefile b/Makefile index 64b1325..3dcd2c1 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,12 @@ GOFILES = \ ctlrpc.go \ ctl.go +ifeq ($(GOOS),windows) + GOFILES += signal_windows.go +else + GOFILES += signal_unix.go +endif + .PHONY: grumble grumble: pkg $(GC) $(GCFLAGS) -o $(TARG).$(O) $(GOFILES) diff --git a/grumble.go b/grumble.go index 106d9c2..339dbf3 100644 --- a/grumble.go +++ b/grumble.go @@ -9,7 +9,6 @@ import ( "flag" "fmt" "os" - "os/signal" "log" "net" "sqlite" @@ -233,6 +232,7 @@ func main() { if len(servers) > 0 { ticker := time.NewTicker(10e9) // 10 secs + go SignalHandler() for { select { case <-ticker.C: @@ -243,23 +243,6 @@ func main() { continue } } - - case sig := <-signal.Incoming: - if sig != signal.SIGINT && sig != signal.SIGTERM { - continue - } - - for sid, s := range servers { - err := s.FreezeToFile(filepath.Join(*datadir, fmt.Sprintf("%v", sid))) - if err != nil { - log.Printf("Unable to freeze server %v: %s", sid, err.String()) - continue - } - - log.Printf("Server %v frozen", sid) - } - - return } } } diff --git a/signal_unix.go b/signal_unix.go new file mode 100644 index 0000000..0990e9e --- /dev/null +++ b/signal_unix.go @@ -0,0 +1,29 @@ +// Copyright (c) 2011 The Grumble Authors +// The use of this source code is goverened by a BSD-style +// license that can be found in the LICENSE-file. + +package main + +import ( + "fmt" + "log" + "os/signal" + "path/filepath" +) + +func SignalHandler() { + for { + sig := <-signal.Incoming + if sig != signal.SIGINT && sig != signal.SIGTERM { + continue + } + for sid, s := range servers { + err := s.FreezeToFile(filepath.Join(*datadir, fmt.Sprintf("%v", sid))) + if err != nil { + log.Printf("Unable to freeze server %v: %s", sid, err.String()) + continue + } + log.Printf("Server %v frozen", sid) + } + } +} diff --git a/signal_windows.go b/signal_windows.go new file mode 100644 index 0000000..becf18a --- /dev/null +++ b/signal_windows.go @@ -0,0 +1,8 @@ +// Copyright (c) 2011 The Grumble Authors +// The use of this source code is goverened by a BSD-style +// license that can be found in the LICENSE-file. + +package main + +func SignalHandler() { +}