Skip to content

Commit dec0849

Browse files
committed
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 <ptikhomirov@virtuozzo.com>
1 parent 75e685d commit dec0849

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

daemon/stats/collector_unix.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ func (s *Collector) getSystemCPUUsage() (uint64, error) {
7272

7373
func (s *Collector) getNumberOnlineCPUs() (uint32, error) {
7474
i, err := C.sysconf(C._SC_NPROCESSORS_ONLN)
75-
if err != nil {
75+
// According to POSIX - errno is undefined after successful
76+
// sysconf, and can be non-zero in several cases, so look for
77+
// error in returned value not in errno.
78+
// (https://sourceware.org/bugzilla/show_bug.cgi?id=21536)
79+
if i == -1 {
7680
return 0, err
7781
}
7882
return uint32(i), nil

0 commit comments

Comments
 (0)