]> Cypherpunks.ru repositories - gostls13.git/commitdiff
os, syscall: move rlimit code to syscall
authorIan Lance Taylor <iant@golang.org>
Mon, 13 Mar 2023 22:20:11 +0000 (15:20 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 15 Mar 2023 17:18:32 +0000 (17:18 +0000)
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 <cherryyz@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/syscall/rlimit.go [moved from src/os/rlimit.go with 83% similarity]
src/syscall/rlimit_darwin.go [moved from src/os/rlimit_darwin.go with 79% similarity]
src/syscall/rlimit_stub.go [moved from src/os/rlimit_stub.go with 82% similarity]
src/syscall/rlimit_test.go [moved from src/os/rlimit_test.go with 91% similarity]

similarity index 83%
rename from src/os/rlimit.go
rename to src/syscall/rlimit.go
index e0d0ef9b621d2397667ed2fdaaeb750ed2517fad..2049200c00e822766e31a992553469942598dcf1 100644 (file)
@@ -4,9 +4,7 @@
 
 //go:build unix
 
-package os
-
-import "syscall"
+package syscall
 
 // Some systems set an artificially low soft limit on open file count, for compatibility
 // with code that uses select and its hard-coded maximum file descriptor
@@ -23,10 +21,10 @@ import "syscall"
 // Code that really wants Go to leave the limit alone can set the hard limit,
 // which Go of course has no choice but to respect.
 func init() {
-       var lim syscall.Rlimit
-       if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim); err == nil && lim.Cur != lim.Max {
+       var lim Rlimit
+       if err := Getrlimit(RLIMIT_NOFILE, &lim); err == nil && lim.Cur != lim.Max {
                lim.Cur = lim.Max
                adjustFileLimit(&lim)
-               syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim)
+               Setrlimit(RLIMIT_NOFILE, &lim)
        }
 }
similarity index 79%
rename from src/os/rlimit_darwin.go
rename to src/syscall/rlimit_darwin.go
index b28982a83a193ddd9851603d96aced2b4f51df17..73e49646b30896d4d92eaf0e8fdc4f3f4a631494 100644 (file)
@@ -4,15 +4,13 @@
 
 //go:build darwin
 
-package os
-
-import "syscall"
+package syscall
 
 // adjustFileLimit adds per-OS limitations on the Rlimit used for RLIMIT_NOFILE. See rlimit.go.
-func adjustFileLimit(lim *syscall.Rlimit) {
+func adjustFileLimit(lim *Rlimit) {
        // On older macOS, setrlimit(RLIMIT_NOFILE, lim) with lim.Cur = infinity fails.
        // Set to the value of kern.maxfilesperproc instead.
-       n, err := syscall.SysctlUint32("kern.maxfilesperproc")
+       n, err := SysctlUint32("kern.maxfilesperproc")
        if err != nil {
                return
        }
similarity index 82%
rename from src/os/rlimit_stub.go
rename to src/syscall/rlimit_stub.go
index cbe28400c5b47d9826dfc7bbfb4523a7f4d9f062..e8f839dd991a38d2e3ee698955aec34d3d3f665c 100644 (file)
@@ -4,9 +4,7 @@
 
 //go:build aix || dragonfly || freebsd || linux || netbsd || openbsd || solaris
 
-package os
-
-import "syscall"
+package syscall
 
 // adjustFileLimit adds per-OS limitations on the Rlimit used for RLIMIT_NOFILE. See rlimit.go.
-func adjustFileLimit(lim *syscall.Rlimit) {}
+func adjustFileLimit(lim *Rlimit) {}
similarity index 91%
rename from src/os/rlimit_test.go
rename to src/syscall/rlimit_test.go
index c02e36f3f76a682f07c59ec4526ed7d261549896..e48f45e3aacb75d07db1ff0ff2f33334f2677409 100644 (file)
@@ -2,10 +2,10 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package os_test
+package syscall_test
 
 import (
-       "os"
+       "os"
        "runtime"
        "testing"
 )
@@ -24,9 +24,9 @@ func TestOpenFileLimit(t *testing.T) {
                fileCount = 768
        }
 
-       var files []*File
+       var files []*os.File
        for i := 0; i < fileCount; i++ {
-               f, err := Open("rlimit.go")
+               f, err := os.Open("rlimit.go")
                if err != nil {
                        t.Error(err)
                        break