New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/sys/unix: Select signature on BSDs omits integer return value, unlike Linux etc #34458
Comments
CC @tklauser This part of the Is it possible that the Darwin version of this syscall does not return the number of file descriptors from the kernel, and instead computes it on the caller side? What about the other *BSDs? |
OpenBSD certainly claims to "select() returns the total number of ready descriptors in all the sets". And looking at kernel code it looks like yes. |
The same seems to be true for Darwin (didn't find an online source for this, checked locally on macOS 10.14), FreeBSD, NetBSD and DragonflyBSD. Probably also Solaris and Illumos. On Darwin I also checked that rr, ww, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
defer rr.Close()
defer ww.Close()
if _, err := ww.Write([]byte("HELLO GOPHER")); err != nil {
t.Fatal(err)
}
rFdSet := &unix.FdSet{}
fd := rr.Fd()
// FD_SET(fd, rFdSet), this needs NFDBITS from sys/select.h as a generated const
rFdSet.Bits[fd/unix.NFDBITS] |= (1 << (fd % unix.NFDBITS))
n, err := unix.Select(int(fd+1), rFdSet, nil, nil, nil)
if err != nil {
t.Fatalf("Select: %v", err)
}
if n != 1 {
t.Fatalf("Select: expected 1 ready file descriptors, got %v", n)
} How would we go about changing |
The default answer to that is: "Syscall must always be guarded with build tags." -- https://go-proverbs.github.io That said, this signature should probably match everywhere. Let's just fix x/sys/unix but not syscall. |
Change https://golang.org/cl/196802 mentions this issue: |
Right. Yeah fixing |
And exposing |
We are not going to make a breaking change to the syscall package. We can do that if absolutely necessary, but this is not absolutely necessary. We can change x/sys/unix for a good enough reason. |
https://golang.org/cl/196802 will add |
Change https://golang.org/cl/196805 mentions this issue: |
Change https://golang.org/cl/196806 mentions this issue: |
Change https://golang.org/cl/196807 mentions this issue: |
CL 196802 did not properly re-generate the definition of Select after changing the //sys comment. Updates golang/go#34458 Change-Id: I035468487163f48393fc777dde691737fce41aa8 Reviewed-on: https://go-review.googlesource.com/c/sys/+/196805 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Make Select's signature on Solaris match the one on Linux and return the number of ready file descriptors. Updates golang/go#34458 Change-Id: I118c4c35cbc83dba015ef357ce9bef44c9165ec1 Reviewed-on: https://go-review.googlesource.com/c/sys/+/196807 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Adjust TestSelect on Linux to match the Darwin/*BSD changes in CL 196802. Updates golang/go#34458 Change-Id: Ia17fdadf7091001ea785391da23aaf9d3ec4ac5e Reviewed-on: https://go-review.googlesource.com/c/sys/+/196806 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes. It's still in the code in HEAD.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Tried to build this on OpenBSD, which builds fine on Linux:
What did you expect to see?
Since OpenBSD has the same POSIX semantics for Select, as far as I know, as Linux, I expect the same function prototype and for the example above to successfully build.
What did you see instead?
On OpenBSD (and Mac, and all BSDs?) the above fails to build because syscall.Select and unix.Select only return error, not
(int, error)
.How can I make portable programs when Go removes my ability to call
Select
?The text was updated successfully, but these errors were encountered: