-
Notifications
You must be signed in to change notification settings - Fork 0
/
ulimit_unix.go
47 lines (39 loc) · 922 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
43
44
45
46
47
// +build linux darwin
package main
import (
"fmt"
"os"
"strconv"
"syscall"
)
var ipfsFileDescNum = uint64(2048)
func init() {
if val := os.Getenv("IPFS_FD_MAX"); val != "" {
n, err := strconv.Atoi(val)
if err != nil {
log.Error("bad value for IPFS_FD_MAX: %s", err)
} else {
ipfsFileDescNum = uint64(n)
}
}
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)
}
if rLimit.Cur < ipfsFileDescNum {
if rLimit.Max < ipfsFileDescNum {
rLimit.Max = ipfsFileDescNum
}
fmt.Printf("Adjusting current ulimit to %d.\n", ipfsFileDescNum)
rLimit.Cur = ipfsFileDescNum
}
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
return fmt.Errorf("error setting ulimit: %s", err)
}
return nil
}