1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #33471 from Snorch/sysconf-nrprocessors-onln-errno

Do not treat C.sysconf(C._SC_NPROCESSORS_ONLN) non-zero errno as error
This commit is contained in:
Sebastiaan van Stijn 2017-06-06 10:22:41 +02:00 committed by GitHub
commit 8b1adf55c2

View file

@ -72,7 +72,11 @@ func (s *Collector) getSystemCPUUsage() (uint64, error) {
func (s *Collector) getNumberOnlineCPUs() (uint32, error) {
i, err := C.sysconf(C._SC_NPROCESSORS_ONLN)
if err != nil {
// According to POSIX - errno is undefined after successful
// sysconf, and can be non-zero in several cases, so look for
// error in returned value not in errno.
// (https://sourceware.org/bugzilla/show_bug.cgi?id=21536)
if i == -1 {
return 0, err
}
return uint32(i), nil