Setrlimit in linux

This commit is contained in:
zhengyu 2019-08-19 19:42:14 +08:00
parent e6f1c8928e
commit e52c0f814e
3 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,25 @@
// +build linux
package utils
import (
"syscall"
"github.com/nadoo/glider/common/log"
)
func InitRLimit() {
var rlim syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim)
if err != nil {
log.F("get rlimit error: " + err.Error())
return
}
rlim.Cur = 1048576
rlim.Max = 1048576
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)
if err != nil {
log.F("set rlimit error: " + err.Error())
return
}
}

View File

@ -0,0 +1,7 @@
// +build !linux
package utils
func InitRLimit() {
}

View File

@ -7,6 +7,7 @@ import (
"syscall"
"github.com/nadoo/glider/common/log"
"github.com/nadoo/glider/common/utils"
"github.com/nadoo/glider/dns"
"github.com/nadoo/glider/ipset"
"github.com/nadoo/glider/proxy"
@ -46,6 +47,8 @@ func main() {
}
}
utils.InitRLimit()
// global rule dialer
dialer := rule.NewDialer(conf.rules, strategy.NewDialer(conf.Forward, &conf.StrategyConfig))