From 11e412c29ccfec59bea80d3acc87072b4ea0a67f Mon Sep 17 00:00:00 2001 From: "Sean E. Russell" Date: Sat, 30 May 2020 05:32:26 -0500 Subject: Fixes #97 Updating the modules files for FreeBSD log fix --- devices/temp_freebsd.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'devices') diff --git a/devices/temp_freebsd.go b/devices/temp_freebsd.go index 0916122..6686c32 100644 --- a/devices/temp_freebsd.go +++ b/devices/temp_freebsd.go @@ -3,6 +3,7 @@ package devices import ( + "log" "os/exec" "strconv" "strings" @@ -11,6 +12,10 @@ import ( ) func init() { + if len(devs()) == 0 { + log.Println("temp: no thermal sensors found") + return + } RegisterTemp(update) } @@ -43,3 +48,22 @@ func update(temps map[string]int) map[string]error { return errors } + +func devs() []string { + rv := make([]string, 0, len(sensorOIDS)) + // Check that thermal sensors are really available; they aren't in VMs + bs, err := exec.Command("sysctl", "-a").Output() + if err != nil { + log.Printf("temp: failure to get system information %s", err.Error()) + return []string{} + } + for k, _ := range sensorOIDS { + idx := strings.Index(string(bs), k) + if idx < 0 { + log.Printf("temp: no device %s found", k) + } else { + rv = append(rv, k) + } + } + return rv +} -- cgit v1.2.3