Skip to content

Commit

Permalink
Use syscalls in sys/unix to tweak ulimit
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Apr 5, 2019
1 parent ebab291 commit 2689ef7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions commands/limit_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package commands

import (
"syscall"
"golang.org/x/sys/unix"

"github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman"
Expand All @@ -33,8 +33,8 @@ func newLimitCmd() *limitCmd {
Long: `Hugo will inspect the current ulimit settings on the system.
This is primarily to ensure that Hugo can watch enough files on some OSs`,
RunE: func(cmd *cobra.Command, args []string) error {
var rLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
var rLimit unix.Rlimit
err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rLimit)
if err != nil {
return newSystemError("Error Getting Rlimit ", err)
}
Expand All @@ -44,11 +44,11 @@ This is primarily to ensure that Hugo can watch enough files on some OSs`,
jww.FEEDBACK.Println("Attempting to increase limit")
rLimit.Max = 999999
rLimit.Cur = 999999
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
err = unix.Setrlimit(unix.RLIMIT_NOFILE, &rLimit)
if err != nil {
return newSystemError("Error Setting rLimit ", err)
}
err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
err = unix.Getrlimit(unix.RLIMIT_NOFILE, &rLimit)
if err != nil {
return newSystemError("Error Getting rLimit ", err)
}
Expand All @@ -62,15 +62,15 @@ This is primarily to ensure that Hugo can watch enough files on some OSs`,
}

func tweakLimit() {
var rLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
var rLimit unix.Rlimit
err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rLimit)
if err != nil {
jww.ERROR.Println("Unable to obtain rLimit", err)
}
if rLimit.Cur < rLimit.Max {
if true || rLimit.Cur < rLimit.Max {
rLimit.Max = 64000
rLimit.Cur = 64000
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
err = unix.Setrlimit(unix.RLIMIT_NOFILE, &rLimit)
if err != nil {
jww.WARN.Println("Unable to increase number of open files limit", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ require (
golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd // indirect
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc // indirect
golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc
golang.org/x/text v0.3.0
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.2.2
Expand Down

0 comments on commit 2689ef7

Please sign in to comment.