From e7e27398498b1d91458ed24cbffcb19111fe5941 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Thu, 17 Sep 2015 16:28:15 +1000 Subject: [PATCH] os: touch up the EINTR retry loop in OpenFile In particular, don't use goto and do restrict the behavior to darwin. This addresses comments from http://golang.org/cl/14484. Change-Id: I5b99e1762d1c5b27fdd12b72a5c6d981f6a92f0f Reviewed-on: https://go-review.googlesource.com/14673 Reviewed-by: Rob Pike --- src/os/file_unix.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/os/file_unix.go b/src/os/file_unix.go index 36b2a608ff..68d0a6e64c 100644 --- a/src/os/file_unix.go +++ b/src/os/file_unix.go @@ -90,14 +90,19 @@ func OpenFile(name string, flag int, perm FileMode) (*File, error) { } } -retry: - r, e := syscall.Open(name, flag|syscall.O_CLOEXEC, syscallMode(perm)) - if e != nil { + var r int + for { + var e error + r, e = syscall.Open(name, flag|syscall.O_CLOEXEC, syscallMode(perm)) + if e == nil { + break + } + // On OS X, sigaction(2) doesn't guarantee that SA_RESTART will cause // open(2) to be restarted for regular files. This is easy to reproduce on // fuse file systems (see http://golang.org/issue/11180). - if e == syscall.EINTR { - goto retry + if runtime.GOOS == "darwin" && e == syscall.EINTR { + continue } return nil, &PathError{"open", name, e} -- 2.48.1