lotus/lib/ulimit/ulimit_unix.go

28 lines
512 B
Go
Raw Normal View History

2020-03-22 21:08:22 +00:00
// +build darwin linux netbsd openbsd
package ulimit
import (
2020-03-22 21:39:27 +00:00
unix "golang.org/x/sys/unix"
2020-03-22 21:08:22 +00:00
)
func init() {
supportsFDManagement = true
getLimit = unixGetLimit
setLimit = unixSetLimit
}
func unixGetLimit() (uint64, uint64, error) {
rlimit := unix.Rlimit{}
err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlimit)
return rlimit.Cur, rlimit.Max, err
}
func unixSetLimit(soft uint64, max uint64) error {
rlimit := unix.Rlimit{
Cur: soft,
Max: max,
}
return unix.Setrlimit(unix.RLIMIT_NOFILE, &rlimit)
}