Commit 801364e0 authored by Tobias Klauser's avatar Tobias Klauser Committed by Tobias Klauser

unix: add Select on Solaris

Change-Id: I9e0e4bc6b9f8700d72e891d623f948db6af7d64b
Reviewed-on: https://go-review.googlesource.com/85255
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent d818ba11
......@@ -658,6 +658,7 @@ func Poll(fds []PollFd, timeout int) (n int, err error) {
//sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
//sys Rmdir(path string) (err error)
//sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = lseek
//sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
//sysnb Setegid(egid int) (err error)
//sysnb Seteuid(euid int) (err error)
//sysnb Setgid(gid int) (err error)
......
......@@ -9,10 +9,31 @@ package unix_test
import (
"os/exec"
"testing"
"time"
"golang.org/x/sys/unix"
)
func TestSelect(t *testing.T) {
err := unix.Select(0, nil, nil, nil, &unix.Timeval{Sec: 0, Usec: 0})
if err != nil {
t.Fatalf("Select: %v", err)
}
dur := 150 * time.Millisecond
tv := unix.NsecToTimeval(int64(dur))
start := time.Now()
err = unix.Select(0, nil, nil, nil, &tv)
took := time.Since(start)
if err != nil {
t.Fatalf("Select: %v", err)
}
if took < dur {
t.Errorf("Select: timeout should have been at least %v, got %v", dur, took)
}
}
func TestStatvfs(t *testing.T) {
if err := unix.Statvfs("", nil); err == nil {
t.Fatal(`Statvfs("") expected failure`)
......
......@@ -95,6 +95,7 @@ import (
//go:cgo_import_dynamic libc_renameat renameat "libc.so"
//go:cgo_import_dynamic libc_rmdir rmdir "libc.so"
//go:cgo_import_dynamic libc_lseek lseek "libc.so"
//go:cgo_import_dynamic libc_select select "libc.so"
//go:cgo_import_dynamic libc_setegid setegid "libc.so"
//go:cgo_import_dynamic libc_seteuid seteuid "libc.so"
//go:cgo_import_dynamic libc_setgid setgid "libc.so"
......@@ -220,6 +221,7 @@ import (
//go:linkname procRenameat libc_renameat
//go:linkname procRmdir libc_rmdir
//go:linkname proclseek libc_lseek
//go:linkname procSelect libc_select
//go:linkname procSetegid libc_setegid
//go:linkname procSeteuid libc_seteuid
//go:linkname procSetgid libc_setgid
......@@ -346,6 +348,7 @@ var (
procRenameat,
procRmdir,
proclseek,
procSelect,
procSetegid,
procSeteuid,
procSetgid,
......@@ -1264,6 +1267,14 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
return
}
func Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) {
_, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procSelect)), 5, uintptr(n), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), 0)
if e1 != 0 {
err = e1
}
return
}
func Setegid(egid int) (err error) {
_, _, e1 := rawSysvicall6(uintptr(unsafe.Pointer(&procSetegid)), 1, uintptr(egid), 0, 0, 0, 0, 0)
if e1 != 0 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment