Skip to content

Commit 491153a

Browse files
ianlancetaylorgopherbot
authored andcommitted
os, syscall: move rlimit code to syscall
In CL 393354 the os package was changed to raise the open file rlimit at program start. That code is not inherently tied to the os package. This CL moves it into the syscall package. This is in preparation for future changes to restore the original soft rlimit when exec'ing a new program. For #46279 Change-Id: I981401b0345d017fd39fdd3dfbb58069be36c272 Reviewed-on: https://go-review.googlesource.com/c/go/+/476096 Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Tobias Klauser <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 1d06667 commit 491153a

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

src/os/rlimit.go renamed to src/syscall/rlimit.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
//go:build unix
66

7-
package os
8-
9-
import "syscall"
7+
package syscall
108

119
// Some systems set an artificially low soft limit on open file count, for compatibility
1210
// with code that uses select and its hard-coded maximum file descriptor
@@ -23,10 +21,10 @@ import "syscall"
2321
// Code that really wants Go to leave the limit alone can set the hard limit,
2422
// which Go of course has no choice but to respect.
2523
func init() {
26-
var lim syscall.Rlimit
27-
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim); err == nil && lim.Cur != lim.Max {
24+
var lim Rlimit
25+
if err := Getrlimit(RLIMIT_NOFILE, &lim); err == nil && lim.Cur != lim.Max {
2826
lim.Cur = lim.Max
2927
adjustFileLimit(&lim)
30-
syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim)
28+
Setrlimit(RLIMIT_NOFILE, &lim)
3129
}
3230
}

src/os/rlimit_darwin.go renamed to src/syscall/rlimit_darwin.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
//go:build darwin
66

7-
package os
8-
9-
import "syscall"
7+
package syscall
108

119
// adjustFileLimit adds per-OS limitations on the Rlimit used for RLIMIT_NOFILE. See rlimit.go.
12-
func adjustFileLimit(lim *syscall.Rlimit) {
10+
func adjustFileLimit(lim *Rlimit) {
1311
// On older macOS, setrlimit(RLIMIT_NOFILE, lim) with lim.Cur = infinity fails.
1412
// Set to the value of kern.maxfilesperproc instead.
15-
n, err := syscall.SysctlUint32("kern.maxfilesperproc")
13+
n, err := SysctlUint32("kern.maxfilesperproc")
1614
if err != nil {
1715
return
1816
}

src/os/rlimit_stub.go renamed to src/syscall/rlimit_stub.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
//go:build aix || dragonfly || freebsd || linux || netbsd || openbsd || solaris
66

7-
package os
8-
9-
import "syscall"
7+
package syscall
108

119
// adjustFileLimit adds per-OS limitations on the Rlimit used for RLIMIT_NOFILE. See rlimit.go.
12-
func adjustFileLimit(lim *syscall.Rlimit) {}
10+
func adjustFileLimit(lim *Rlimit) {}

src/os/rlimit_test.go renamed to src/syscall/rlimit_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package os_test
5+
package syscall_test
66

77
import (
8-
. "os"
8+
"os"
99
"runtime"
1010
"testing"
1111
)
@@ -24,9 +24,9 @@ func TestOpenFileLimit(t *testing.T) {
2424
fileCount = 768
2525
}
2626

27-
var files []*File
27+
var files []*os.File
2828
for i := 0; i < fileCount; i++ {
29-
f, err := Open("rlimit.go")
29+
f, err := os.Open("rlimit.go")
3030
if err != nil {
3131
t.Error(err)
3232
break

0 commit comments

Comments
 (0)