diff options
| author | Ian Lance Taylor <iant@golang.org> | 2023-03-13 20:59:14 -0700 |
|---|---|---|
| committer | Ian Lance Taylor <iant@google.com> | 2023-03-15 17:21:30 +0000 |
| commit | f5eef58e4381259cbd84b3f2074c79607fb5c821 (patch) | |
| tree | 1405152029a813b5e8efa81c1cd10212a6eb12a0 /src/syscall/syscall_linux.go | |
| parent | 491153a71ab2bae3fe9a586489320573448511ab (diff) | |
| download | go-f5eef58e4381259cbd84b3f2074c79607fb5c821.tar.xz | |
syscall: restore original NOFILE rlimit in child process
If we increased the NOFILE rlimit when starting the program,
restore the original rlimit when forking a child process.
For #46279
Change-Id: Ia5d2af9ef435e5932965c15eec2e428d2130d230
Reviewed-on: https://go-review.googlesource.com/c/go/+/476097
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Bypass: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/syscall/syscall_linux.go')
| -rw-r--r-- | src/syscall/syscall_linux.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/syscall/syscall_linux.go b/src/syscall/syscall_linux.go index bf9d85637a..618b2e6d42 100644 --- a/src/syscall/syscall_linux.go +++ b/src/syscall/syscall_linux.go @@ -1058,7 +1058,7 @@ func Getpgrp() (pid int) { //sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error) //sys Nanosleep(time *Timespec, leftover *Timespec) (err error) //sys PivotRoot(newroot string, putold string) (err error) = SYS_PIVOT_ROOT -//sysnb prlimit(pid int, resource int, newlimit *Rlimit, old *Rlimit) (err error) = SYS_PRLIMIT64 +//sysnb prlimit1(pid int, resource int, newlimit *Rlimit, old *Rlimit) (err error) = SYS_PRLIMIT64 //sys read(fd int, p []byte) (n int, err error) //sys Removexattr(path string, attr string) (err error) //sys Setdomainname(p []byte) (err error) @@ -1261,3 +1261,14 @@ func Munmap(b []byte) (err error) { //sys Munlock(b []byte) (err error) //sys Mlockall(flags int) (err error) //sys Munlockall() (err error) + +// prlimit changes a resource limit. We use a single definition so that +// we can tell StartProcess to not restore the original NOFILE limit. +// This is unexported but can be called from x/sys/unix. +func prlimit(pid int, resource int, newlimit *Rlimit, old *Rlimit) (err error) { + err = prlimit1(pid, resource, newlimit, old) + if err == nil && newlimit != nil && resource == RLIMIT_NOFILE { + origRlimitNofile.Store(Rlimit{0, 0}) + } + return err +} |
