From: Yuval Pavel Zholkover Date: Fri, 19 Apr 2019 12:41:38 +0000 (+0300) Subject: os: disable the use of netpoll on directories as well on *BSDs X-Git-Tag: go1.13beta1~618 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=059f2d4a467465183820710df43a234f02d9c255;p=gostls13.git os: disable the use of netpoll on directories as well on *BSDs Follow up CL 156379. Updates #19093 Change-Id: I5ea3177fc5911d3af71cbb32584249e419e9d4a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/172937 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/os/file_unix.go b/src/os/file_unix.go index 1cd8000dd4..89c05b2657 100644 --- a/src/os/file_unix.go +++ b/src/os/file_unix.go @@ -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 } }