diff --git a/galene.go b/galene.go index 09f0862..f8a05f7 100644 --- a/galene.go +++ b/galene.go @@ -104,9 +104,9 @@ func main() { }() } - n, err := limit.Nofile(0xFFFF) + n, err := limit.Nofile() if err != nil { - log.Printf("Couldn't set file descriptor limit: %v", err) + log.Printf("Couldn't get file descriptor limit: %v", err) } else if n < 0xFFFF { log.Printf("File descriptor limit is %v, please increase it!", n) } diff --git a/limit/limit.go b/limit/limit.go index 5f87f47..f1e52eb 100644 --- a/limit/limit.go +++ b/limit/limit.go @@ -1,7 +1,7 @@ -// +build !linux +//go:build !unix package limit -func Nofile(desired uint64) (uint64, error) { - return desired, nil +func Nofile() (uint64, error) { + return 0xFFFF, nil } diff --git a/limit/limit_unix.go b/limit/limit_unix.go index 25f03fc..fba9616 100644 --- a/limit/limit_unix.go +++ b/limit/limit_unix.go @@ -1,4 +1,4 @@ -// +build linux +//go:build unix package limit @@ -6,38 +6,13 @@ import ( "golang.org/x/sys/unix" ) -func Nofile(desired uint64) (uint64, error) { - var old unix.Rlimit +func Nofile() (uint64, error) { + var limit unix.Rlimit - err := unix.Getrlimit(unix.RLIMIT_NOFILE, &old) + err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit) if err != nil { return 0, err } - if old.Cur >= desired { - return old.Cur, nil - } - - if old.Max < desired { - limit := unix.Rlimit{ - Cur: desired, - Max: desired, - } - err := unix.Setrlimit(unix.RLIMIT_NOFILE, &limit) - if err == nil { - return limit.Cur, nil - } - - desired = old.Max - } - - limit := unix.Rlimit{ - Cur: desired, - Max: old.Max, - } - err = unix.Setrlimit(unix.RLIMIT_NOFILE, &limit) - if err != nil { - return old.Cur, err - } - return limit.Cur, nil + return uint64(limit.Cur), nil }