1 // Copyright (c) 2013-2014 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
5 // +build !windows,!plan9
19 // SetLimits raises some process limits to values which allow btcd and
20 // associated utilities to run.
21 func SetLimits() error {
22 var rLimit syscall.Rlimit
24 err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
28 if rLimit.Cur > fileLimitWant {
31 if rLimit.Max < fileLimitMin {
32 err = fmt.Errorf("need at least %v file descriptors",
36 if rLimit.Max < fileLimitWant {
37 rLimit.Cur = rLimit.Max
39 rLimit.Cur = fileLimitWant
41 err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
44 rLimit.Cur = fileLimitMin
45 err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)