Catch SIGINT and SIGTERM - shutdown SDR functions.

Fixes #204.
pull/213/head
Christopher Young 2016-01-19 10:40:40 -05:00
rodzic e0dde8d5de
commit 57a9fbf393
2 zmienionych plików z 39 dodań i 0 usunięć

Wyświetl plik

@ -21,9 +21,11 @@ import (
"io/ioutil"
"log"
"os"
"os/signal"
"runtime"
"strconv"
"strings"
"syscall"
"time"
humanize "github.com/dustin/go-humanize"
@ -1200,8 +1202,23 @@ func openReplayFile(fn string) ReadCloser {
}
var stratuxClock *monotonic
var sigs = make(chan os.Signal, 1) // Signal catch channel (shutdown).
// Graceful shutdown.
func signalWatcher() {
sig := <-sigs
log.Printf("signal caught: %s - shutting down.\n", sig.String())
// Shut down SDRs.
sdrKill()
//TODO: Any other graceful shutdown functions.
os.Exit(1)
}
func main() {
// Catch signals for graceful shutdown.
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go signalWatcher()
stratuxClock = NewMonotonic() // Start our "stratux clock".
// replayESFilename := flag.String("eslog", "none", "ES Log filename")

Wyświetl plik

@ -284,6 +284,17 @@ func (e *ES) shutdown() {
var devMap = map[int]string{0: "", 1: ""}
var sdrShutdown bool
func sdrKill() {
// Send signal to shutdown to sdrWatcher().
sdrShutdown = true
// Spin until all devices have been de-initialized.
for UATDev != nil || ESDev != nil {
time.Sleep(1 * time.Second)
}
}
// Watch for config/device changes.
func sdrWatcher() {
stopCheckingUATUntil := time.Time{}
@ -292,6 +303,17 @@ func sdrWatcher() {
for {
time.Sleep(1 * time.Second)
if sdrShutdown {
if UATDev != nil {
UATDev.shutdown()
UATDev = nil
}
if ESDev != nil {
ESDev.shutdown()
ESDev = nil
}
return
}
count := rtl.GetDeviceCount()
atomic.StoreUint32(&globalStatus.Devices, uint32(count))
// log.Println("DeviceCount...", count)