]> Cypherpunks repositories - gostls13.git/commitdiff
internal/poll, os/exec, runtime: replace PollDescriptor by IsPollDescriptor
authorClément Chigot <clement.chigot@atos.net>
Fri, 2 Nov 2018 09:02:38 +0000 (10:02 +0100)
committerIan Lance Taylor <iant@golang.org>
Fri, 2 Nov 2018 13:43:23 +0000 (13:43 +0000)
This commit changes poll.PollDescriptor by poll.IsPollDescriptor. This
is needed for OS like AIX which have more than one FD using inside their
netpoll implementation.

Change-Id: I49e12a8d74045c501e19fdd8527cf166a3c64850
Reviewed-on: https://go-review.googlesource.com/c/146938
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/internal/poll/fd_plan9.go
src/internal/poll/fd_poll_nacljs.go
src/internal/poll/fd_poll_runtime.go
src/os/exec/exec_test.go
src/runtime/netpoll.go

index 107f4545233394d43dc61348d2c6d5aaeeffc882..fce22859319ee48934a8d9819f2ced10a09f3270 100644 (file)
@@ -193,10 +193,10 @@ func isInterrupted(err error) bool {
        return err != nil && stringsHasSuffix(err.Error(), "interrupted")
 }
 
-// PollDescriptor returns the descriptor being used by the poller,
-// or ^uintptr(0) if there isn't one. This is only used for testing.
-func PollDescriptor() uintptr {
-       return ^uintptr(0)
+// IsPollDescriptor returns true if fd is the descriptor being used by the poller.
+// This is only used for testing.
+func IsPollDescriptor(fd uintptr) bool {
+       return false
 }
 
 // RawControl invokes the user-defined function f for a non-IO
index 832dddb4aa4470927dcf946dd37c08640d9f004f..e0d3f976f15e42059d65801f3b6710ff1ba796cd 100644 (file)
@@ -92,8 +92,8 @@ func setDeadlineImpl(fd *FD, t time.Time, mode int) error {
        return nil
 }
 
-// PollDescriptor returns the descriptor being used by the poller,
-// or ^uintptr(0) if there isn't one. This is only used for testing.
-func PollDescriptor() uintptr {
-       return ^uintptr(0)
+// IsPollDescriptor returns true if fd is the descriptor being used by the poller.
+// This is only used for testing.
+func IsPollDescriptor(fd uintptr) bool {
+       return false
 }
index f4540a60f689bd83aa769bc2d02c27a5c415c05d..2ee8e7c2c9e3030ce9399734888188bcb48122c3 100644 (file)
@@ -19,7 +19,6 @@ import (
 func runtimeNano() int64
 
 func runtime_pollServerInit()
-func runtime_pollServerDescriptor() uintptr
 func runtime_pollOpen(fd uintptr) (uintptr, int)
 func runtime_pollClose(ctx uintptr)
 func runtime_pollWait(ctx uintptr, mode int) int
@@ -27,6 +26,7 @@ func runtime_pollWaitCanceled(ctx uintptr, mode int) int
 func runtime_pollReset(ctx uintptr, mode int) int
 func runtime_pollSetDeadline(ctx uintptr, d int64, mode int)
 func runtime_pollUnblock(ctx uintptr)
+func runtime_isPollServerDescriptor(fd uintptr) bool
 
 type pollDesc struct {
        runtimeCtx uintptr
@@ -154,8 +154,8 @@ func setDeadlineImpl(fd *FD, t time.Time, mode int) error {
        return nil
 }
 
-// PollDescriptor returns the descriptor being used by the poller,
-// or ^uintptr(0) if there isn't one. This is only used for testing.
-func PollDescriptor() uintptr {
-       return runtime_pollServerDescriptor()
+// IsPollDescriptor returns true if fd is the descriptor being used by the poller.
+// This is only used for testing.
+func IsPollDescriptor(fd uintptr) bool {
+       return runtime_isPollServerDescriptor(fd)
 }
index 558345ff632c956ae26a7e665a0d4a6acfdf5c62..3e6b7bb95e1580a974f96df63b4b1c84eff8e1c9 100644 (file)
@@ -459,7 +459,7 @@ func basefds() uintptr {
        // The poll (epoll/kqueue) descriptor can be numerically
        // either between stderr and the testlog-fd, or after
        // testlog-fd.
-       if poll.PollDescriptor() == n {
+       if poll.IsPollDescriptor(n) {
                n++
        }
        for _, arg := range os.Args {
@@ -472,7 +472,7 @@ func basefds() uintptr {
 
 func closeUnexpectedFds(t *testing.T, m string) {
        for fd := basefds(); fd <= 101; fd++ {
-               if fd == poll.PollDescriptor() {
+               if poll.IsPollDescriptor(fd) {
                        continue
                }
                err := os.NewFile(fd, "").Close()
@@ -734,6 +734,8 @@ func TestHelperProcess(*testing.T) {
                ofcmd = "fstat"
        case "plan9":
                ofcmd = "/bin/cat"
+       case "aix":
+               ofcmd = "procfiles"
        }
 
        args := os.Args
@@ -837,7 +839,7 @@ func TestHelperProcess(*testing.T) {
                        // Now verify that there are no other open fds.
                        var files []*os.File
                        for wantfd := basefds() + 1; wantfd <= 100; wantfd++ {
-                               if wantfd == poll.PollDescriptor() {
+                               if poll.IsPollDescriptor(wantfd) {
                                        continue
                                }
                                f, err := os.Open(os.Args[0])
@@ -851,6 +853,8 @@ func TestHelperProcess(*testing.T) {
                                        switch runtime.GOOS {
                                        case "plan9":
                                                args = []string{fmt.Sprintf("/proc/%d/fd", os.Getpid())}
+                                       case "aix":
+                                               args = []string{fmt.Sprint(os.Getpid())}
                                        default:
                                                args = []string{"-p", fmt.Sprint(os.Getpid())}
                                        }
index 4f4abfcd2cb0213afe947c4a869f61748258612c..75db8c6c2fe3a5e6f2ecfe10f224dc1612b12479 100644 (file)
@@ -93,12 +93,19 @@ func netpollinited() bool {
        return atomic.Load(&netpollInited) != 0
 }
 
-//go:linkname poll_runtime_pollServerDescriptor internal/poll.runtime_pollServerDescriptor
-
-// poll_runtime_pollServerDescriptor returns the descriptor being used,
-// or ^uintptr(0) if the system does not use a poll descriptor.
-func poll_runtime_pollServerDescriptor() uintptr {
-       return netpolldescriptor()
+//go:linkname poll_runtime_isPollServerDescriptor internal/poll.runtime_isPollServerDescriptor
+
+// poll_runtime_isPollServerDescriptor returns true if fd is a
+// descriptor being used by netpoll.
+func poll_runtime_isPollServerDescriptor(fd uintptr) bool {
+       fds := netpolldescriptor()
+       if GOOS != "aix" {
+               return fd == fds
+       } else {
+               // AIX have a pipe in its netpoll implementation.
+               // Therefore, two fd are returned by netpolldescriptor using a mask.
+               return fd == fds&0xFFFF || fd == (fds>>16)&0xFFFF
+       }
 }
 
 //go:linkname poll_runtime_pollOpen internal/poll.runtime_pollOpen