func ignoringEINTR(fn func() error) error {
return fn()
}
+
+func ignoringEINTR2[T any](fn func() (T, error)) (T, error) {
+ return fn()
+}
}
}
}
+
+// ignoringEINTR2 is ignoringEINTR, but returning an additional value.
+func ignoringEINTR2[T any](fn func() (T, error)) (T, error) {
+ for {
+ v, err := fn()
+ if err != syscall.EINTR {
+ return v, err
+ }
+ }
+}
func readlink(name string) (string, error) {
for len := 128; ; len *= 2 {
b := make([]byte, len)
- var (
- n int
- e error
- )
- for {
- n, e = fixCount(syscall.Readlink(name, b))
- if e != syscall.EINTR {
- break
- }
- }
+ n, err := ignoringEINTR2(func() (int, error) {
+ return fixCount(syscall.Readlink(name, b))
+ })
// buffer too small
- if (runtime.GOOS == "aix" || runtime.GOOS == "wasip1") && e == syscall.ERANGE {
+ if (runtime.GOOS == "aix" || runtime.GOOS == "wasip1") && err == syscall.ERANGE {
continue
}
- if e != nil {
- return "", &PathError{Op: "readlink", Path: name, Err: e}
+ if err != nil {
+ return "", &PathError{Op: "readlink", Path: name, Err: err}
}
if n < len {
return string(b[0:n]), nil
// If the operating system provides a Getwd call, use it.
if syscall.ImplementsGetwd {
- for {
- dir, err = syscall.Getwd()
- if err != syscall.EINTR {
- break
- }
- }
+ dir, err = ignoringEINTR2(syscall.Getwd)
// Linux returns ENAMETOOLONG if the result is too long.
// Some BSD systems appear to return EINVAL.
// FreeBSD systems appear to use ENOMEM
// we are going to (try to) remove the file.
// The contents of this file are not relevant for test caching.
func openDirAt(dirfd int, name string) (*File, error) {
- var r int
- for {
- var e error
- r, e = unix.Openat(dirfd, name, O_RDONLY|syscall.O_CLOEXEC|syscall.O_DIRECTORY|syscall.O_NOFOLLOW, 0)
- if e == nil {
- break
- }
-
- // See comment in openFileNolog.
- if e == syscall.EINTR {
- continue
- }
-
- return nil, e
+ r, err := ignoringEINTR2(func() (int, error) {
+ return unix.Openat(dirfd, name, O_RDONLY|syscall.O_CLOEXEC|syscall.O_DIRECTORY|syscall.O_NOFOLLOW, 0)
+ })
+ if err != nil {
+ return nil, err
}
if !supportsCloseOnExec {