aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/utils/fdlimit_freebsd.go10
-rw-r--r--cmd/utils/fdlimit_test.go12
-rw-r--r--cmd/utils/fdlimit_unix.go10
-rw-r--r--cmd/utils/fdlimit_windows.go6
4 files changed, 37 insertions, 1 deletions
diff --git a/cmd/utils/fdlimit_freebsd.go b/cmd/utils/fdlimit_freebsd.go
index 4cb5013c8..f9ed8937e 100644
--- a/cmd/utils/fdlimit_freebsd.go
+++ b/cmd/utils/fdlimit_freebsd.go
@@ -52,3 +52,13 @@ func getFdLimit() (int, error) {
}
return int(limit.Cur), nil
}
+
+// getFdMaxLimit retrieves the maximum number of file descriptors this process is
+// allowed to request for itself.
+func getFdMaxLimit() (int, error) {
+ var limit syscall.Rlimit
+ if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
+ return 0, err
+ }
+ return int(limit.Max), nil
+}
diff --git a/cmd/utils/fdlimit_test.go b/cmd/utils/fdlimit_test.go
index 0a950a6c9..48489cf4c 100644
--- a/cmd/utils/fdlimit_test.go
+++ b/cmd/utils/fdlimit_test.go
@@ -16,12 +16,22 @@
package utils
-import "testing"
+import (
+ "fmt"
+ "testing"
+)
// TestFileDescriptorLimits simply tests whether the file descriptor allowance
// per this process can be retrieved.
func TestFileDescriptorLimits(t *testing.T) {
target := 4096
+ hardlimit, err := getFdMaxLimit()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if hardlimit < target {
+ t.Skip(fmt.Sprintf("system limit is less than desired test target: %d < %d", hardlimit, target))
+ }
if limit, err := getFdLimit(); err != nil || limit <= 0 {
t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err)
diff --git a/cmd/utils/fdlimit_unix.go b/cmd/utils/fdlimit_unix.go
index 08e153bbd..c08d1fab0 100644
--- a/cmd/utils/fdlimit_unix.go
+++ b/cmd/utils/fdlimit_unix.go
@@ -48,3 +48,13 @@ func getFdLimit() (int, error) {
}
return int(limit.Cur), nil
}
+
+// getFdMaxLimit retrieves the maximum number of file descriptors this process is
+// allowed to request for itself.
+func getFdMaxLimit() (int, error) {
+ var limit syscall.Rlimit
+ if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
+ return 0, err
+ }
+ return int(limit.Max), nil
+}
diff --git a/cmd/utils/fdlimit_windows.go b/cmd/utils/fdlimit_windows.go
index 53aad3d7a..f239683d2 100644
--- a/cmd/utils/fdlimit_windows.go
+++ b/cmd/utils/fdlimit_windows.go
@@ -39,3 +39,9 @@ func getFdLimit() (int, error) {
// Please see raiseFdLimit for the reason why we use hard coded 16K as the limit
return 16384, nil
}
+
+// getFdMaxLimit retrieves the maximum number of file descriptors this process is
+// allowed to request for itself.
+func getFdMaxLimit() (int, error) {
+ return getFdLimit()
+}