]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.12] os: enable the close-on-exec flag for openFdAt
authorBaokun Lee <nototon@gmail.com>
Thu, 1 Aug 2019 16:31:57 +0000 (00:31 +0800)
committerIan Lance Taylor <iant@golang.org>
Fri, 2 Aug 2019 04:53:33 +0000 (04:53 +0000)
There's a race here with fork/exec, enable the close-on-exec flag
for the new file descriptor.

Updates #33405
Fixes #33424

Change-Id: Ib1e405c3b48b11c867f183fd13eff8b73d95e3b4
Reviewed-on: https://go-review.googlesource.com/c/go/+/188537
Run-TryBot: Baokun Lee <nototon@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
(cherry picked from commit 2d6ee6e89a4b30c7528d2977df4e1aa86651e4e4)
Reviewed-on: https://go-review.googlesource.com/c/go/+/188538
Run-TryBot: Ian Lance Taylor <iant@golang.org>

src/os/removeall_at.go

index 330963b3541159602ea7ec6ee06604b02fcb291e..c7de8a32a8f248e72a206f4e41a5c7c589de7d23 100644 (file)
@@ -157,7 +157,7 @@ func openFdAt(dirfd int, name string) (*File, error) {
        var r int
        for {
                var e error
-               r, e = unix.Openat(dirfd, name, O_RDONLY, 0)
+               r, e = unix.Openat(dirfd, name, O_RDONLY|syscall.O_CLOEXEC, 0)
                if e == nil {
                        break
                }