Explicitly check for the rc 3 in call to getloadavg(). Reorder logic.

This commit is contained in:
Karsten Weiss 2017-05-14 13:07:54 +02:00
parent af358ec800
commit b73af72853
2 changed files with 6 additions and 6 deletions

View File

@ -32,8 +32,8 @@ import "C"
func getLoad() ([]float64, error) {
var loadavg [3]C.double
samples := C.getloadavg(&loadavg[0], 3)
if samples > 0 {
return []float64{float64(loadavg[0]), float64(loadavg[1]), float64(loadavg[2])}, nil
if samples != 3 {
return nil, errors.New("failed to get load average")
}
return nil, errors.New("failed to get load average")
return []float64{float64(loadavg[0]), float64(loadavg[1]), float64(loadavg[2])}, nil
}

View File

@ -26,8 +26,8 @@ import "C"
func getLoad() ([]float64, error) {
var loadavg [3]C.double
samples := C.getloadavg(&loadavg[0], 3)
if samples > 0 {
return []float64{float64(loadavg[0]), float64(loadavg[1]), float64(loadavg[2])}, nil
if samples != 3 {
return nil, errors.New("failed to get load average")
}
return nil, errors.New("failed to get load average")
return []float64{float64(loadavg[0]), float64(loadavg[1]), float64(loadavg[2])}, nil
}