mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-07 09:17:49 +08:00
Raising FD limits was erroring when the OS's max was at the maximum signed integer value. Switched the code to using uint64 instead of int64. fixed #5495 License: MIT Signed-off-by: Rob Deutsch <rdeutschob@gmail.com>
37 lines
780 B
Go
37 lines
780 B
Go
// +build freebsd
|
|
|
|
package util
|
|
|
|
import (
|
|
"errors"
|
|
"math"
|
|
|
|
unix "gx/ipfs/QmVGjyM9i2msKvLXwh9VosCTgP4mL91kC7hDmqnwTTx6Hu/sys/unix"
|
|
)
|
|
|
|
func init() {
|
|
supportsFDManagement = true
|
|
getLimit = freebsdGetLimit
|
|
setLimit = freebsdSetLimit
|
|
}
|
|
|
|
func freebsdGetLimit() (uint64, uint64, error) {
|
|
rlimit := unix.Rlimit{}
|
|
err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlimit)
|
|
if (rlimit.Cur < 0) || (rlimit.Max < 0) {
|
|
return 0, 0, errors.New("invalid rlimits")
|
|
}
|
|
return uint64(rlimit.Cur), uint64(rlimit.Max), err
|
|
}
|
|
|
|
func freebsdSetLimit(soft uint64, max uint64) error {
|
|
if (soft > math.MaxInt64) || (max > math.MaxInt64) {
|
|
return errors.New("invalid rlimits")
|
|
}
|
|
rlimit := unix.Rlimit{
|
|
Cur: int64(soft),
|
|
Max: int64(max),
|
|
}
|
|
return unix.Setrlimit(unix.RLIMIT_NOFILE, &rlimit)
|
|
}
|