From 008c8eb2066f93f93ca696bec5f255ac529b653d Mon Sep 17 00:00:00 2001 From: Pavel Tikhomirov Date: Thu, 1 Jun 2017 14:01:55 +0300 Subject: [PATCH] Do not treat C.sysconf(C._SC_NPROCESSORS_ONLN) non-zero errno as error Treat return code -1 as error instead. People from glibc say that errno is undefined in case of successful sysconf call according to POSIX standard: Glibc bug: https://sourceware.org/bugzilla/show_bug.cgi?id=21536 More over in sysconf man it is wrongly said that "errno is not changed" on success. So I've created a bug to man-pages: https://bugzilla.kernel.org/show_bug.cgi?id=195955 Background: Glibc's sysconf(_SC_NPROCESSORS_ONLN) changes errno to ENOENT, if there is no /sys/devices/system/cpu/online file, while the call itself is successful. In Virtuozzo containers we prohibit most of sysfs files for security reasons. So we have Run():daemon /stats/collector.go infinitely loop never actualy collecting stats from publisher pairs. v2: add comment Signed-off-by: Pavel Tikhomirov Upstream-commit: dec084962eab41eb20b1808955de34cfec4fc8b3 Component: engine --- components/engine/daemon/stats/collector_unix.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/engine/daemon/stats/collector_unix.go b/components/engine/daemon/stats/collector_unix.go index 5ad9658690..cd522e07ce 100644 --- a/components/engine/daemon/stats/collector_unix.go +++ b/components/engine/daemon/stats/collector_unix.go @@ -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