mirror of
https://github.com/jech/galene.git
synced 2024-11-24 01:25:58 +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:
parent
82de29b6d0
commit
90a0a2e318
3 changed files with 10 additions and 35 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue