From de8ddd97accb417450db014d1f45723515cb5d80 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 8 Mar 2022 11:13:37 +0100 Subject: [PATCH] syscall: add Pipe2 on solaris and use it for forkExecPipe Other platforms already define Pipe2, so add it for solaris as well. Change-Id: If0d2dfc9a3613479fb4611a673a20a4aa0af0b2b Reviewed-on: https://go-review.googlesource.com/c/go/+/390714 Trust: Tobias Klauser Run-TryBot: Tobias Klauser Trust: Matt Layher TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/syscall/forkpipe.go | 2 +- src/syscall/forkpipe2.go | 2 +- src/syscall/syscall_solaris.go | 15 +++++++++++++++ src/syscall/zsyscall_solaris_amd64.go | 13 +++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/syscall/forkpipe.go b/src/syscall/forkpipe.go index 6f7d29ce67..5082abc41c 100644 --- a/src/syscall/forkpipe.go +++ b/src/syscall/forkpipe.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build aix || darwin || solaris +//go:build aix || darwin package syscall diff --git a/src/syscall/forkpipe2.go b/src/syscall/forkpipe2.go index 312244c0d8..6ab1391c12 100644 --- a/src/syscall/forkpipe2.go +++ b/src/syscall/forkpipe2.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build dragonfly || freebsd || netbsd || openbsd +//go:build dragonfly || freebsd || netbsd || openbsd || solaris package syscall diff --git a/src/syscall/syscall_solaris.go b/src/syscall/syscall_solaris.go index f44a9e25ac..3c50343d84 100644 --- a/src/syscall/syscall_solaris.go +++ b/src/syscall/syscall_solaris.go @@ -63,6 +63,21 @@ func Pipe(p []int) (err error) { return } +//sysnb pipe2(p *[2]_C_int, flags int) (err error) + +func Pipe2(p []int, flags int) error { + if len(p) != 2 { + return EINVAL + } + var pp [2]_C_int + err := pipe2(&pp, flags) + if err == nil { + p[0] = int(pp[0]) + p[1] = int(pp[1]) + } + return err +} + func (sa *SockaddrInet4) sockaddr() (unsafe.Pointer, _Socklen, error) { if sa.Port < 0 || sa.Port > 0xFFFF { return nil, 0, EINVAL diff --git a/src/syscall/zsyscall_solaris_amd64.go b/src/syscall/zsyscall_solaris_amd64.go index 2d8cdfd280..dad0580027 100644 --- a/src/syscall/zsyscall_solaris_amd64.go +++ b/src/syscall/zsyscall_solaris_amd64.go @@ -7,6 +7,7 @@ package syscall import "unsafe" +//go:cgo_import_dynamic libc_pipe2 pipe2 "libc.so" //go:cgo_import_dynamic libc_Getcwd getcwd "libc.so" //go:cgo_import_dynamic libc_getgroups getgroups "libc.so" //go:cgo_import_dynamic libc_setgroups setgroups "libc.so" @@ -91,6 +92,7 @@ import "unsafe" //go:cgo_import_dynamic libc_getexecname getexecname "libc.so" //go:cgo_import_dynamic libc_utimensat utimensat "libc.so" +//go:linkname libc_pipe2 libc_pipe2 //go:linkname libc_Getcwd libc_Getcwd //go:linkname libc_getgroups libc_getgroups //go:linkname libc_setgroups libc_setgroups @@ -178,6 +180,7 @@ import "unsafe" type libcFunc uintptr var ( + libc_pipe2, libc_Getcwd, libc_getgroups, libc_setgroups, @@ -265,6 +268,16 @@ var ( // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func pipe2(p *[2]_C_int, flags int) (err error) { + _, _, e1 := rawSysvicall6(uintptr(unsafe.Pointer(&libc_pipe2)), 2, uintptr(unsafe.Pointer(p)), uintptr(flags), 0, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getcwd(buf []byte) (n int, err error) { var _p0 *byte if len(buf) > 0 { -- 2.50.0