os, internal/poll: loop on EINTR for all file syscalls

When using a FUSE file system, any system call that touches the file
system can return EINTR.

Fixes #40846

Change-Id: I25d32da22cec08dea81ab297291a85ad72db2df7
Reviewed-on: https://go-review.googlesource.com/c/go/+/249178
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Ian Lance Taylor 2020-08-18 16:46:24 -07:00
parent 18239be10a
commit 6b420169d7
12 changed files with 133 additions and 34 deletions

View file

@ -39,7 +39,9 @@ func rename(oldname, newname string) error {
return &LinkError{"rename", oldname, newname, syscall.EEXIST}
}
}
err = syscall.Rename(oldname, newname)
err = ignoringEINTR(func() error {
return syscall.Rename(oldname, newname)
})
if err != nil {
return &LinkError{"rename", oldname, newname, err}
}
@ -129,7 +131,9 @@ func newFile(fd uintptr, name string, kind newFileKind) *File {
switch runtime.GOOS {
case "darwin", "dragonfly", "freebsd", "netbsd", "openbsd":
var st syscall.Stat_t
err := syscall.Fstat(fdi, &st)
err := ignoringEINTR(func() error {
return syscall.Fstat(fdi, &st)
})
typ := st.Mode & syscall.S_IFMT
// Don't try to use kqueue with regular files on *BSDs.
// On FreeBSD a regular file is always
@ -264,7 +268,10 @@ func (f *File) seek(offset int64, whence int) (ret int64, err error) {
// If the file is a symbolic link, it changes the size of the link's target.
// If there is an error, it will be of type *PathError.
func Truncate(name string, size int64) error {
if e := syscall.Truncate(name, size); e != nil {
e := ignoringEINTR(func() error {
return syscall.Truncate(name, size)
})
if e != nil {
return &PathError{"truncate", name, e}
}
return nil
@ -277,11 +284,15 @@ func Remove(name string) error {
// whether name is a file or directory.
// Try both: it is cheaper on average than
// doing a Stat plus the right one.
e := syscall.Unlink(name)
e := ignoringEINTR(func() error {
return syscall.Unlink(name)
})
if e == nil {
return nil
}
e1 := syscall.Rmdir(name)
e1 := ignoringEINTR(func() error {
return syscall.Rmdir(name)
})
if e1 == nil {
return nil
}
@ -316,7 +327,9 @@ func tempDir() string {
// Link creates newname as a hard link to the oldname file.
// If there is an error, it will be of type *LinkError.
func Link(oldname, newname string) error {
e := syscall.Link(oldname, newname)
e := ignoringEINTR(func() error {
return syscall.Link(oldname, newname)
})
if e != nil {
return &LinkError{"link", oldname, newname, e}
}
@ -326,7 +339,9 @@ func Link(oldname, newname string) error {
// Symlink creates newname as a symbolic link to oldname.
// If there is an error, it will be of type *LinkError.
func Symlink(oldname, newname string) error {
e := syscall.Symlink(oldname, newname)
e := ignoringEINTR(func() error {
return syscall.Symlink(oldname, newname)
})
if e != nil {
return &LinkError{"symlink", oldname, newname, e}
}
@ -365,7 +380,16 @@ func (f *File) readdir(n int) (fi []FileInfo, err error) {
func Readlink(name string) (string, error) {
for len := 128; ; len *= 2 {
b := make([]byte, len)
n, e := fixCount(syscall.Readlink(name, b))
var (
n int
e error
)
for {
n, e = fixCount(syscall.Readlink(name, b))
if e != syscall.EINTR {
break
}
}
// buffer too small
if runtime.GOOS == "aix" && e == syscall.ERANGE {
continue