1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-24 09:35:57 +01:00

Don't attempt to set file descriptor limit.

Recent versions of Go do it at startup, so only print
a warning if the limit is too low.
This commit is contained in:
Juliusz Chroboczek 2024-05-27 00:02:31 +02:00
parent 82de29b6d0
commit 90a0a2e318
3 changed files with 10 additions and 35 deletions

View file

@ -104,9 +104,9 @@ func main() {
}() }()
} }
n, err := limit.Nofile(0xFFFF) n, err := limit.Nofile()
if err != nil { 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 { } else if n < 0xFFFF {
log.Printf("File descriptor limit is %v, please increase it!", n) log.Printf("File descriptor limit is %v, please increase it!", n)
} }

View file

@ -1,7 +1,7 @@
// +build !linux //go:build !unix
package limit package limit
func Nofile(desired uint64) (uint64, error) { func Nofile() (uint64, error) {
return desired, nil return 0xFFFF, nil
} }

View file

@ -1,4 +1,4 @@
// +build linux //go:build unix
package limit package limit
@ -6,38 +6,13 @@ import (
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
func Nofile(desired uint64) (uint64, error) { func Nofile() (uint64, error) {
var old unix.Rlimit var limit unix.Rlimit
err := unix.Getrlimit(unix.RLIMIT_NOFILE, &old) err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit)
if err != nil { if err != nil {
return 0, err return 0, err
} }
if old.Cur >= desired { return uint64(limit.Cur), nil
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
} }