Skip to content

Commit 22a80e7

Browse files
kolyshkingopherbot
authored andcommitted
syscall: Setrlimit: always clean rlimitNofileCache
Since the introduction of origRlimitNofileCache in CL 476097 the only way to disable restoring RLIMIT_NOFILE before calling execve syscall (os.StartProcess etc) is this: var r syscall.Rlimit syscall.Getrlimit(syscall.RLIMIT_NOFILE, &r) syscall.Setrlimit(syscall.RLIMIT_NOFILE, &r) The problem is, this only works when setrlimit syscall succeeds, which is not possible in some scenarios. Let's assume that if a user calls syscall.Setrlimit, they unconditionally want to disable restoring the original rlimit. For #66797. Change-Id: I20d0365df4bd6a5c3cc8c22b0c0db87a25b52746 Reviewed-on: https://go-review.googlesource.com/c/go/+/588076 Run-TryBot: Kirill Kolyshkin <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> TryBot-Bypass: Ian Lance Taylor <[email protected]>
1 parent 5c7d774 commit 22a80e7

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/syscall/rlimit.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,10 @@ func init() {
5050
}
5151

5252
func Setrlimit(resource int, rlim *Rlimit) error {
53-
err := setrlimit(resource, rlim)
54-
if err == nil && resource == RLIMIT_NOFILE {
53+
if resource == RLIMIT_NOFILE {
5554
// Store nil in origRlimitNofile to tell StartProcess
5655
// to not adjust the rlimit in the child process.
5756
origRlimitNofile.Store(nil)
5857
}
59-
return err
58+
return setrlimit(resource, rlim)
6059
}

0 commit comments

Comments
 (0)