Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ulimit: handle freebsd ulimit code separately from the rest of the un… #3450

Merged
merged 1 commit into from
Dec 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cmd/ipfs/ulimit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"os"
"strconv"
)

var ipfsFileDescNum = uint64(1024)

func init() {
if val := os.Getenv("IPFS_FD_MAX"); val != "" {
n, err := strconv.Atoi(val)
if err != nil {
log.Errorf("bad value for IPFS_FD_MAX: %s", err)
} else {
ipfsFileDescNum = uint64(n)
}
}
}
44 changes: 44 additions & 0 deletions cmd/ipfs/ulimit_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// +build freebsd

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)
}

ipfsFileDescNum := int64(ipfsFileDescNum)

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
}
14 changes: 1 addition & 13 deletions cmd/ipfs/ulimit_unix.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
// +build darwin freebsd linux netbsd openbsd
// +build darwin linux netbsd openbsd

package main

import (
"fmt"
"os"
"strconv"
"syscall"
)

var ipfsFileDescNum = uint64(1024)

func init() {
if val := os.Getenv("IPFS_FD_MAX"); val != "" {
n, err := strconv.Atoi(val)
if err != nil {
log.Errorf("bad value for IPFS_FD_MAX: %s", err)
} else {
ipfsFileDescNum = uint64(n)
}
}
fileDescriptorCheck = checkAndSetUlimit
}

Expand Down