Skip to content

Commit eb72a30

Browse files
os: make openFdAt act like openFileNolog
- add EINTR loop on Darwin - return PathError on error - call newFile rather than NewFile This tries to minimize the possibility of any future changes. It would be nice to put openFdAt in the same file as openFileNolog, but build tags forbid. Updates #29983 Change-Id: I866002416d6473fbfd80ff6ef09b2bc4607f2934 Reviewed-on: https://go-review.googlesource.com/c/160181 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Damien Neil <[email protected]>
1 parent f1d662f commit eb72a30

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/os/file_unix.go

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ func epipecheck(file *File, e error) {
186186
const DevNull = "/dev/null"
187187

188188
// openFileNolog is the Unix implementation of OpenFile.
189+
// Changes here should be reflected in openFdAt, if relevant.
189190
func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
190191
setSticky := false
191192
if !supportsCreateWithStickyBit && flag&O_CREATE != 0 && perm&ModeSticky != 0 {

src/os/removeall_at.go

+26-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package os
99
import (
1010
"internal/syscall/unix"
1111
"io"
12+
"runtime"
1213
"syscall"
1314
)
1415

@@ -128,11 +129,31 @@ func removeAllFrom(parent *File, path string) error {
128129
return unlinkError
129130
}
130131

131-
func openFdAt(fd int, path string) (*File, error) {
132-
fd, err := unix.Openat(fd, path, O_RDONLY, 0)
133-
if err != nil {
134-
return nil, err
132+
// openFdAt opens path relative to the directory in fd.
133+
// Other than that this should act like openFileNolog.
134+
// This acts like openFileNolog rather than OpenFile because
135+
// we are going to (try to) remove the file.
136+
// The contents of this file are not relevant for test caching.
137+
func openFdAt(dirfd int, name string) (*File, error) {
138+
var r int
139+
for {
140+
var e error
141+
r, e = unix.Openat(dirfd, name, O_RDONLY, 0)
142+
if e == nil {
143+
break
144+
}
145+
146+
// See comment in openFileNolog.
147+
if runtime.GOOS == "darwin" && e == syscall.EINTR {
148+
continue
149+
}
150+
151+
return nil, &PathError{"openat", name, e}
152+
}
153+
154+
if !supportsCloseOnExec {
155+
syscall.CloseOnExec(r)
135156
}
136157

137-
return NewFile(uintptr(fd), path), nil
158+
return newFile(uintptr(r), name, kindOpenFile), nil
138159
}

0 commit comments

Comments
 (0)