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 }