From b324148faa331637e5a958ccc8c1804b585daacd Mon Sep 17 00:00:00 2001 From: mpl Date: Fri, 12 May 2017 17:54:49 +0200 Subject: [PATCH] pkg/osutil: fix for getrlimit on FreeBSD maxFD did not build on FreeBSD because syscall.Getrlimit returns an int64 instead of a uint64. So we convert the result to a uint64. Credits to @SamWhited on github for the report + fix. Fixes #925 Change-Id: I15ab682f2f80463279d24ece21a45c23f9a431e6 --- pkg/osutil/syscall_posix.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/osutil/syscall_posix.go b/pkg/osutil/syscall_posix.go index 84d988324..7c3150fbc 100644 --- a/pkg/osutil/syscall_posix.go +++ b/pkg/osutil/syscall_posix.go @@ -60,5 +60,14 @@ func maxFD() (uint64, error) { } return 0, fmt.Errorf("ulimit error: %v", err) } - return rlim.Cur, nil + // On FreeBSD Getrlimit returns an int64, because (among other things) the + // maximum value for the Rlimit struct fields, called RLIM_INFINITY used to + // be defined as -1. + // According to + // https://github.com/freebsd/freebsd/blob/master/sys/sys/resource.h , it looks + // like it is now defined as + // #define RLIM_INFINITY ((rlim_t)(((__uint64_t)1 << 63) - 1)) + // which is the maximum positive value of an int64. So casting to an uint64 + // should be ok. + return uint64(rlim.Cur), nil }