]> Cypherpunks repositories - gostls13.git/commitdiff
os: touch up the EINTR retry loop in OpenFile
authorAaron Jacobs <jacobsa@google.com>
Thu, 17 Sep 2015 06:28:15 +0000 (16:28 +1000)
committerRob Pike <r@golang.org>
Thu, 17 Sep 2015 14:49:30 +0000 (14:49 +0000)
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 <r@golang.org>
src/os/file_unix.go

index 36b2a608ff8021a95cd86deab4217b044bfa6944..68d0a6e64c28eb6e0ba4fa668df82eac585eae47 100644 (file)
@@ -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}