]> Cypherpunks repositories - gostls13.git/commitdiff
os: disable the use of netpoll on directories as well on *BSDs
authorYuval Pavel Zholkover <paulzhol@gmail.com>
Fri, 19 Apr 2019 12:41:38 +0000 (15:41 +0300)
committerIan Lance Taylor <iant@golang.org>
Fri, 19 Apr 2019 19:24:47 +0000 (19:24 +0000)
Follow up CL 156379.

Updates #19093

Change-Id: I5ea3177fc5911d3af71cbb32584249e419e9d4a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/172937
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/os/file_unix.go

index 1cd8000dd4294acb58b7f3460faf72be37a879bf..89c05b26572afd9d75d51e1591042aa45ad40416 100644 (file)
@@ -122,25 +122,27 @@ func newFile(fd uintptr, name string, kind newFileKind) *File {
        // we assume they know what they are doing so we allow it to be
        // used with kqueue.
        if kind == kindOpenFile {
-               var st syscall.Stat_t
                switch runtime.GOOS {
-               case "dragonfly", "freebsd", "netbsd", "openbsd":
+               case "darwin", "dragonfly", "freebsd", "netbsd", "openbsd":
+                       var st syscall.Stat_t
+                       err := 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
                        // reported as ready for writing.
                        // On Dragonfly, NetBSD and OpenBSD the fd is signaled
                        // only once as ready (both read and write).
                        // Issue 19093.
-                       if err := syscall.Fstat(fdi, &st); err == nil && st.Mode&syscall.S_IFMT == syscall.S_IFREG {
+                       // Also don't add directories to the netpoller.
+                       if err == nil && (typ == syscall.S_IFREG || typ == syscall.S_IFDIR) {
                                pollable = false
                        }
 
-               case "darwin":
                        // In addition to the behavior described above for regular files,
                        // on Darwin, kqueue does not work properly with fifos:
                        // closing the last writer does not cause a kqueue event
                        // for any readers. See issue #24164.
-                       if err := syscall.Fstat(fdi, &st); err == nil && (st.Mode&syscall.S_IFMT == syscall.S_IFIFO || st.Mode&syscall.S_IFMT == syscall.S_IFREG) {
+                       if runtime.GOOS == "darwin" && typ == syscall.S_IFIFO {
                                pollable = false
                        }
                }