Skip to content

Commit 5029507

Browse files
committed
Update sensors warning check
1 parent 2c3e14d commit 5029507

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

internal/glance/cli.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,21 @@ func parseCliOptions() (*cliOptions, error) {
9696
func cliSensorsPrint() int {
9797
tempSensors, err := sensors.SensorsTemperatures()
9898
if err != nil {
99-
fmt.Printf("Errors encountered while retrieving list of sensors:\n %v\n", err)
10099
if warns, ok := err.(*sensors.Warnings); ok {
100+
fmt.Printf("Could not retrieve information for some sensors (%v):\n", err)
101101
for _, w := range warns.List {
102102
fmt.Printf(" - %v\n", w)
103103
}
104+
fmt.Println()
105+
} else {
106+
fmt.Printf("Failed to retrieve sensor information: %v\n", err)
107+
return 1
104108
}
105109

106110
return 1
107111
}
108112

109-
if tempSensors == nil || len(tempSensors) == 0 {
113+
if len(tempSensors) == 0 {
110114
fmt.Println("No sensors found")
111115
return 0
112116
}

pkg/sysinfo/sysinfo.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,12 @@ func Collect(req *SystemInfoRequest) (*SystemInfo, []error) {
201201
// currently disabled on Windows because it requires elevated privilidges, otherwise
202202
// keeps returning a single sensor with key "ACPI\\ThermalZone\\TZ00_0" which
203203
// doesn't seem to be the CPU sensor or correspond to anything useful when
204-
// compared against the temperatures Libre Hardware Monitor reports
205-
// also disabled on openbsd because it's not implemented by go-psutil
206-
if runtime.GOOS != "windows" && runtime.GOOS != "openbsd" {
204+
// compared against the temperatures Libre Hardware Monitor reports.
205+
// Also disabled on the bsd's because it's not implemented by go-psutil for them
206+
if runtime.GOOS != "windows" && runtime.GOOS != "openbsd" && runtime.GOOS != "netbsd" && runtime.GOOS != "freebsd" {
207207
sensorReadings, err := sensors.SensorsTemperatures()
208-
if sensorReadings != nil && len(sensorReadings) > 0 {
208+
_, errIsWarning := err.(*sensors.Warnings)
209+
if err == nil || errIsWarning {
209210
if req.CPUTempSensor != "" {
210211
for i := range sensorReadings {
211212
if sensorReadings[i].SensorKey == req.CPUTempSensor {

0 commit comments

Comments
 (0)