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/exec_bsd.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/exec_bsd.go')
| -rw-r--r-- | src/syscall/exec_bsd.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/syscall/exec_bsd.go b/src/syscall/exec_bsd.go index 379875561b..0b0cd24e69 100644 --- a/src/syscall/exec_bsd.go +++ b/src/syscall/exec_bsd.go @@ -64,6 +64,8 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr ngroups, groups uintptr ) + rlim, rlimOK := origRlimitNofile.Load().(Rlimit) + // guard against side effects of shuffling fds below. // Make sure that nextfd is beyond any currently open files so // that we can't run the risk of overwriting any of them. @@ -273,6 +275,11 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr } } + // Restore original rlimit. + if rlimOK && rlim.Cur != 0 { + RawSyscall(SYS_SETRLIMIT, uintptr(RLIMIT_NOFILE), uintptr(unsafe.Pointer(&rlim)), 0) + } + // Time to exec. _, _, err1 = RawSyscall(SYS_EXECVE, uintptr(unsafe.Pointer(argv0)), |
