From b719de0c0791824d7c4e63a73e329230fc0f0f60 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Wed, 2 Dec 2020 19:35:27 +0100 Subject: [PATCH] making module compatible with all platforms --- autofdmax/init_osx.go | 4 +--- autofdmax/{init_windows.go => init_others.go} | 2 +- autofdmax/{init_linux.go => init_unix.go} | 2 +- fdmax.go | 15 +++++++++------ go.mod | 2 ++ go.sum | 2 ++ 6 files changed, 16 insertions(+), 11 deletions(-) rename autofdmax/{init_windows.go => init_others.go} (57%) rename autofdmax/{init_linux.go => init_unix.go} (78%) create mode 100644 go.sum diff --git a/autofdmax/init_osx.go b/autofdmax/init_osx.go index 43ea9f7..e243927 100644 --- a/autofdmax/init_osx.go +++ b/autofdmax/init_osx.go @@ -2,9 +2,7 @@ package autofdmax -import ( - "github.com/projectdiscovery/fdmax" -) +import "github.com/projectdiscovery/fdmax" func init() { fdmax.Set(fdmax.OSXMax) diff --git a/autofdmax/init_windows.go b/autofdmax/init_others.go similarity index 57% rename from autofdmax/init_windows.go rename to autofdmax/init_others.go index 20bd01e..b4badce 100644 --- a/autofdmax/init_windows.go +++ b/autofdmax/init_others.go @@ -1,4 +1,4 @@ -// +build windows +// +build windows freebsd dragonfly plan9 package autofdmax diff --git a/autofdmax/init_linux.go b/autofdmax/init_unix.go similarity index 78% rename from autofdmax/init_linux.go rename to autofdmax/init_unix.go index abb957d..a29a567 100644 --- a/autofdmax/init_linux.go +++ b/autofdmax/init_unix.go @@ -1,4 +1,4 @@ -// +build linux +// +build linux openbsd netbsd package autofdmax diff --git a/fdmax.go b/fdmax.go index 65e8f8a..02498fc 100644 --- a/fdmax.go +++ b/fdmax.go @@ -1,8 +1,11 @@ +// +build !windows + package fdmax import ( "runtime" - "syscall" + + "golang.org/x/sys/unix" ) const ( @@ -16,17 +19,17 @@ type Limits struct { } func Get() (*Limits, 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 nil, err } - return &Limits{Current: rLimit.Cur, Max: rLimit.Max}, nil + return &Limits{Current: uint64(rLimit.Cur), Max: uint64(rLimit.Max)}, nil } func Set(maxLimit uint64) error { - var rLimit syscall.Rlimit + var rLimit unix.Rlimit rLimit.Max = maxLimit rLimit.Cur = maxLimit @@ -35,5 +38,5 @@ func Set(maxLimit uint64) error { rLimit.Cur = OSXMax } - return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit) + return unix.Setrlimit(unix.RLIMIT_NOFILE, &rLimit) } diff --git a/go.mod b/go.mod index 081e604..b930475 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/projectdiscovery/fdmax go 1.14 + +require golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..fe58462 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3 h1:kzM6+9dur93BcC2kVlYl34cHU+TYZLanmpSJHVMmL64= +golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=