diff options
author | Sean E. Russell <ser@ser1.net> | 2020-05-30 05:32:26 -0500 |
---|---|---|
committer | ser <ser@ser1.net> | 2020-05-29 15:23:01 +0000 |
commit | 11e412c29ccfec59bea80d3acc87072b4ea0a67f (patch) | |
tree | 775295d3ef5a968c891c172bbaf0438da0f54fe8 /devices | |
parent | 0900e98abbb47773f0b2ab889158613af9c1a943 (diff) |
Fixes #97
Updating the modules files for FreeBSD
log fix
Diffstat (limited to 'devices')
-rw-r--r-- | devices/temp_freebsd.go | 24 |
1 files changed, 24 insertions, 0 deletions
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 +} |