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

Should verify that the max value is not too big #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions ulimit_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package units

import (
"fmt"

"golang.org/x/sys/unix"
)

// Verify that ulimit values work with current kernel
func (u *Ulimit) Verify() error {
var rlimit unix.Rlimit
if err := unix.Getrlimit(ulimitNameMapping[u.Name], &rlimit); err == nil {
if u.Hard > int64(rlimit.Max) {
return fmt.Errorf("ulimit hard limit (%d) must be less than or equal to hard limit for the current process %d", u.Hard, rlimit.Max)
}
}
return nil
}
24 changes: 24 additions & 0 deletions ulimit_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// +build linux

package units

import (
"fmt"

"golang.org/x/sys/unix"
"testing"
)

func TestParseUlimitTooBig(t *testing.T) {
var rlimit unix.Rlimit
if err := unix.Getrlimit(rlimitNofile, &rlimit); err != nil {
t.Fatalf("Failed to get rlimit of current process %q", err)
}
u, err := ParseUlimit(fmt.Sprintf("nofile=512:%d", rlimit.Max+1))
if err != nil {
t.Fatalf("expected valid value got %q", err)
}
if err := u.Verify(); err == nil {
t.Fatalf("expected invalid hard limit")
}
}
8 changes: 8 additions & 0 deletions ulimit_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// +build !linux

package units

// Verify that ulimit values work with current kernel
func (u *Ulimit) Verify() error {
return nil
}