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
This commit is contained in:
mpl 2017-05-12 17:54:49 +02:00
parent 9d5f0bacb0
commit b324148faa
1 changed files with 10 additions and 1 deletions

View File

@ -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
}