]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: copy original rlimit before modifying
authorMichael Pratt <mpratt@google.com>
Mon, 2 Oct 2023 19:55:29 +0000 (15:55 -0400)
committerGopher Robot <gobot@golang.org>
Mon, 2 Oct 2023 23:19:38 +0000 (23:19 +0000)
CL 531516 converted origRlimitNofile from an atomic.Value to
atomic.Pointer[Rlimit]. i.e., it changed from storing a value to storing
a pointer.

After storing a pointer to lim, the remainder of this function
immediately modifies it, thus mutating the value pointer to by
origRlimitNofile (and thus defeating the point of origRlimitNofile).

This broke the android-amd64-emu builder because it is (apparently) the
only builder where the original RLIMIT_NOFILE Cur != Max.
TestRlimitRestored is skipped on every other builder.

Change-Id: I12076350eeddfd221823ad651e7e7eca59d2bdcd
Reviewed-on: https://go-review.googlesource.com/c/go/+/532100
Run-TryBot: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/syscall/rlimit.go

index fdc0d1bf1f17393d4703c6bc09e68f7d5939e20b..d77341bde9a5394d6a0c3df8bd59d34d77a7fa5a 100644 (file)
@@ -31,9 +31,10 @@ func init() {
        var lim Rlimit
        if err := Getrlimit(RLIMIT_NOFILE, &lim); err == nil && lim.Cur != lim.Max {
                origRlimitNofile.Store(&lim)
-               lim.Cur = lim.Max
-               adjustFileLimit(&lim)
-               setrlimit(RLIMIT_NOFILE, &lim)
+               nlim := lim
+               nlim.Cur = nlim.Max
+               adjustFileLimit(&nlim)
+               setrlimit(RLIMIT_NOFILE, &nlim)
        }
 }