diff options
| author | Keith Randall <keithr@alum.mit.edu> | 2019-04-05 13:01:58 -0700 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2019-04-05 20:40:01 +0000 |
| commit | 06cff114cf786d5f901aa41ac873f9e8bb8e1eba (patch) | |
| tree | dfe7f4758a98759736e75d1dc374af771839f861 /src/syscall/syscall_darwin.go | |
| parent | 68d89bb8e05afc2aa050b4c5ad0df4b3af03c45d (diff) | |
| download | go-06cff114cf786d5f901aa41ac873f9e8bb8e1eba.tar.xz | |
syscall: use openat instead of dup to make a really new file descriptor
Update #31269
Change-Id: I0e7184420055b8dfd23688dab9f9d8cba1fa2485
Reviewed-on: https://go-review.googlesource.com/c/go/+/170892
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/syscall/syscall_darwin.go')
| -rw-r--r-- | src/syscall/syscall_darwin.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/syscall/syscall_darwin.go b/src/syscall/syscall_darwin.go index 7ceceff2c1..422f3d4425 100644 --- a/src/syscall/syscall_darwin.go +++ b/src/syscall/syscall_darwin.go @@ -368,7 +368,13 @@ func writelen(fd int, buf *byte, nbuf int) (n int, err error) { func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { // Simulate Getdirentries using fdopendir/readdir_r/closedir. const ptrSize = unsafe.Sizeof(uintptr(0)) - fd2, err := Dup(fd) + // We need to duplicate the incoming file descriptor + // because the caller expects to retain control of it, but + // fdopendir expects to take control of its argument. + // Just Dup'ing the file descriptor is not enough, as the + // result shares underlying state. Use openat to make a really + // new file descriptor referring to the same directory. + fd2, err := openat(fd, ".", O_RDONLY, 0) if err != nil { return 0, err } |
