-
Notifications
You must be signed in to change notification settings - Fork 0
/
ulimit_unix.go
42 lines (34 loc) · 856 Bytes
/
ulimit_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// +build darwin linux netbsd openbsd
package main
import (
"fmt"
"syscall"
)
func init() {
fileDescriptorCheck = checkAndSetUlimit
}
func checkAndSetUlimit() error {
var rLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
return fmt.Errorf("error getting rlimit: %s", err)
}
var setting bool
if rLimit.Cur < ipfsFileDescNum {
if rLimit.Max < ipfsFileDescNum {
log.Error("adjusting max")
rLimit.Max = ipfsFileDescNum
}
fmt.Printf("Adjusting current ulimit to %d...\n", ipfsFileDescNum)
rLimit.Cur = ipfsFileDescNum
setting = true
}
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
return fmt.Errorf("error setting ulimit: %s", err)
}
if setting {
fmt.Printf("Successfully raised file descriptor limit to %d.\n", ipfsFileDescNum)
}
return nil
}