Skip to content
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: should support Dup2 on Solaris #17042

Closed
pyhalov opened this issue Sep 9, 2016 · 6 comments
Closed

x/sys/unix: should support Dup2 on Solaris #17042

pyhalov opened this issue Sep 9, 2016 · 6 comments

Comments

@pyhalov
Copy link

pyhalov commented Sep 9, 2016

Current go versions don't implement Dup2 for Solaris.
The fix is simple

--- golang-1.6.3/src/syscall/zsyscall_solaris_amd64.go.1        2016-09-09 17:36:48.176495144 +0300
+++ golang-1.6.3/src/syscall/zsyscall_solaris_amd64.go  2016-09-09 17:41:06.974986783 +0300
@@ -21,6 +21,7 @@
 //go:cgo_import_dynamic libc_Chroot chroot "libc.so"
 //go:cgo_import_dynamic libc_Close close "libc.so"
 //go:cgo_import_dynamic libc_Dup dup "libc.so"
+//go:cgo_import_dynamic libc_Dup2 dup2 "libc.so"
 //go:cgo_import_dynamic libc_Exit exit "libc.so"
 //go:cgo_import_dynamic libc_Fchdir fchdir "libc.so"
 //go:cgo_import_dynamic libc_Fchmod fchmod "libc.so"
@@ -104,6 +105,7 @@
 //go:linkname libc_Chroot libc_Chroot
 //go:linkname libc_Close libc_Close
 //go:linkname libc_Dup libc_Dup
+//go:linkname libc_Dup2 libc_Dup2
 //go:linkname libc_Exit libc_Exit
 //go:linkname libc_Fchdir libc_Fchdir
 //go:linkname libc_Fchmod libc_Fchmod
@@ -190,6 +192,7 @@
        libc_Chroot,
        libc_Close,
        libc_Dup,
+       libc_Dup2,
        libc_Exit,
        libc_Fchdir,
        libc_Fchmod,
@@ -412,6 +415,14 @@
        return
 }

+func Dup2(oldfd int, newfd int) (err error) {
+        _, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&libc_Dup2)), 2, uintptr(oldfd), uintptr(newfd), 0, 0, 0, 0)
+        if e1 != 0 {
+                err = errnoErr(e1)
+        }
+        return
+}
+
 func Exit(code int) {
        sysvicall6(uintptr(unsafe.Pointer(&libc_Exit)), 1, uintptr(code), 0, 0, 0, 0, 0)
        return

@ianlancetaylor ianlancetaylor changed the title syscall should support Dup2 on Solaris syscall: should support Dup2 on Solaris Sep 9, 2016
@bradfitz
Copy link
Contributor

bradfitz commented Sep 9, 2016

The syscall package is frozen. See the notes at https://golang.org/pkg/syscall/#pkg-overview

But it doesn't look like it exists in golang.org/x/sys/unix either, so I'll repurpose this bug for that instead.

@bradfitz bradfitz changed the title syscall: should support Dup2 on Solaris x/sys/unix: should support Dup2 on Solaris Sep 9, 2016
@bradfitz bradfitz added this to the Unreleased milestone Sep 9, 2016
@ianlancetaylor
Copy link
Contributor

Admittedly Dup2 is supported by all other Unix systems. Is there some popular program that requires it? I suppose we could consider this to be a special case for the syscall package.

Can you send your patch as a change as described at https://golang.org/doc/contribute.html? If not, please don't send us patches in the issue tracker. It complicates the copyright history. Thanks.

@pyhalov
Copy link
Author

pyhalov commented Sep 9, 2016

I've found that it's missing when tried to build mongo tools, which rely on https://github.com/spacemonkeygo/spacelog. And this one uses Dup2

@minux
Copy link
Member

minux commented Sep 10, 2016 via email

@binarycrusader
Copy link
Contributor

binarycrusader commented Sep 10, 2016

I already added Dup2 among others for Solaris in this commit to sys/unix in revision 68a71b6 for #8609: golang/sys@68a71b6

So the real answer is that spacelog should be using the sys/unix package instead of the syscall package.

@minux minux closed this as completed Sep 10, 2016
@bradfitz
Copy link
Contributor

@pyhalov, please file a bug against https://github.com/spacemonkeygo/spacelog to ask them to use golang.org/x/sys/unix instead of the syscall package.

That said, this is still a little sad for Solaris.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants