github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/server/rlimit_bsd.go (about) 1 // Copyright 2017 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 // +build freebsd dragonfly 12 13 package server 14 15 import ( 16 "math" 17 18 "golang.org/x/sys/unix" 19 ) 20 21 func setRlimitNoFile(limits *rlimit) error { 22 rLimit := unix.Rlimit{Cur: int64(limits.Cur), Max: int64(limits.Max)} 23 return unix.Setrlimit(unix.RLIMIT_NOFILE, &rLimit) 24 } 25 26 func getRlimitNoFile(limits *rlimit) error { 27 var rLimit unix.Rlimit 28 if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rLimit); err != nil { 29 return err 30 } 31 // Some (legacy?) FreeBSD platforms had RLIMIT_INFINITY set to -1. 32 if rLimit.Cur == -1 { 33 limits.Cur = math.MaxUint64 34 } else { 35 limits.Cur = uint64(rLimit.Cur) 36 } 37 if rLimit.Max == -1 { 38 limits.Max = math.MaxUint64 39 } else { 40 limits.Max = uint64(rLimit.Max) 41 } 42 return nil 43 }