From: Kir Kolyshkin Date: Thu, 23 May 2024 20:32:50 +0000 (-0700) Subject: syscall: Setrlimit: always clean rlimitNofileCache X-Git-Tag: go1.23rc1~134 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=22a80e78ea6d65cd0b0726b2907f31b884aeda93;p=gostls13.git 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor TryBot-Bypass: Ian Lance Taylor --- diff --git a/src/syscall/rlimit.go b/src/syscall/rlimit.go index 9547ce8f6d..f94b894b90 100644 --- a/src/syscall/rlimit.go +++ b/src/syscall/rlimit.go @@ -50,11 +50,10 @@ func init() { } func Setrlimit(resource int, rlim *Rlimit) error { - err := setrlimit(resource, rlim) - if err == nil && resource == RLIMIT_NOFILE { + if resource == RLIMIT_NOFILE { // Store nil in origRlimitNofile to tell StartProcess // to not adjust the rlimit in the child process. origRlimitNofile.Store(nil) } - return err + return setrlimit(resource, rlim) }