mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 20:07:45 +08:00
The soft limit is the value that the kernel enforces for the corresponding resource The hard limit acts as a ceiling for the soft limit an unprivileged process may only set its soft limit to a value in the range from 0 up to the hard limit. So in order to make the change in fds count without any error we should inform the user to make the process have CAP_SYS_RESOURCE capability in order to set the hard limit. License: MIT Signed-off-by: hoenirvili <hoenirvili@gmail.com>
28 lines
578 B
Go
28 lines
578 B
Go
// +build darwin linux netbsd openbsd
|
|
|
|
package util
|
|
|
|
import (
|
|
unix "gx/ipfs/QmPXvegq26x982cQjSfbTvSzZXn7GiaMwhhVPHkeTEhrPT/sys/unix"
|
|
)
|
|
|
|
func init() {
|
|
supportsFDManagement = true
|
|
getLimit = unixGetLimit
|
|
setLimit = unixSetLimit
|
|
}
|
|
|
|
func unixGetLimit() (int64, int64, error) {
|
|
rlimit := unix.Rlimit{}
|
|
err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlimit)
|
|
return int64(rlimit.Cur), int64(rlimit.Max), err
|
|
}
|
|
|
|
func unixSetLimit(soft int64, max int64) error {
|
|
rlimit := unix.Rlimit{
|
|
Cur: uint64(soft),
|
|
Max: uint64(max),
|
|
}
|
|
return unix.Setrlimit(unix.RLIMIT_NOFILE, &rlimit)
|
|
}
|