From f8646d9ebec834f9e1582f319d582f6b819d02fa Mon Sep 17 00:00:00 2001 From: Christopher Young Date: Fri, 18 Aug 2017 12:56:58 -0400 Subject: [PATCH] Check system uptime before SDR startup delay. Throw a system error in developer mode if the uptime is greater than 120s and `sdrWatcher()` is restarted (usually a systemd restart). --- main/sdr.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/main/sdr.go b/main/sdr.go index d352277c..d303414f 100644 --- a/main/sdr.go +++ b/main/sdr.go @@ -10,6 +10,7 @@ package main import ( + "fmt" "log" "os/exec" "regexp" @@ -17,6 +18,7 @@ import ( "strings" "sync" "sync/atomic" + "syscall" "time" "../godump978" @@ -471,7 +473,21 @@ func sdrWatcher() { prevUATEnabled := false prevESEnabled := false - time.Sleep(90 * time.Second) + // Get the system (RPi) uptime. + info := syscall.Sysinfo_t{} + err := syscall.Sysinfo(&info) + if err == nil { + // Got system uptime. Delay if and only if the system uptime is less than 120 seconds. This should be plenty of time + // for the RPi to come up and start Stratux. Keeps the delay from happening if the daemon is auto-restarted from systemd. + if info.Uptime < 120 { + time.Sleep(90 * time.Second) + } else if globalSettings.DeveloperMode { + // Throw a "critical error" if developer mode is enabled. Alerts the developer that the daemon was restarted (possibly) + // unexpectedly. + daemonRestartedErr := fmt.Errorf("System uptime %d seconds. Daemon restarted.\n") + addSystemError(daemonRestartedErr) + } + } for { time.Sleep(1 * time.Second)