Skip to content

Commit

Permalink
unix: add Ppoll on openbsd
Browse files Browse the repository at this point in the history
Change-Id: I3a13730e219e6f6df28829cf0d1e193c62073ac8
Reviewed-on: https://go-review.googlesource.com/c/144057
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
tklauser committed Oct 23, 2018
1 parent 8a28ead commit 44b849a
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 0 deletions.
9 changes: 9 additions & 0 deletions unix/syscall_openbsd.go
Expand Up @@ -158,6 +158,15 @@ func IoctlGetTermios(fd int, req uint) (*Termios, error) {
return &value, err
}

//sys ppoll(fds *PollFd, nfds int, timeout *Timespec, sigmask *Sigset_t) (n int, err error)

func Ppoll(fds []PollFd, timeout *Timespec, sigmask *Sigset_t) (n int, err error) {
if len(fds) == 0 {
return ppoll(nil, 0, timeout, sigmask)
}
return ppoll(&fds[0], len(fds), timeout, sigmask)
}

func Uname(uname *Utsname) error {
mib := []_C_int{CTL_KERN, KERN_OSTYPE}
n := unsafe.Sizeof(uname.Sysname)
Expand Down
30 changes: 30 additions & 0 deletions unix/syscall_openbsd_test.go
Expand Up @@ -6,10 +6,40 @@ package unix_test

import (
"testing"
"time"

"golang.org/x/sys/unix"
)

func TestPpoll(t *testing.T) {
f, cleanup := mktmpfifo(t)
defer cleanup()

const timeout = 100 * time.Millisecond

ok := make(chan bool, 1)
go func() {
select {
case <-time.After(10 * timeout):
t.Errorf("Ppoll: failed to timeout after %d", 10*timeout)
case <-ok:
}
}()

fds := []unix.PollFd{{Fd: int32(f.Fd()), Events: unix.POLLIN}}
timeoutTs := unix.NsecToTimespec(int64(timeout))
n, err := unix.Ppoll(fds, &timeoutTs, nil)
ok <- true
if err != nil {
t.Errorf("Ppoll: unexpected error: %v", err)
return
}
if n != 0 {
t.Errorf("Ppoll: wrong number of events: got %v, expected %v", n, 0)
return
}
}

func TestSysctlUvmexp(t *testing.T) {
uvm, err := unix.SysctlUvmexp("vm.uvmexp")
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions unix/types_openbsd.go
Expand Up @@ -261,6 +261,10 @@ const (
POLLWRNORM = C.POLLWRNORM
)

// Signal Sets

type Sigset_t C.sigset_t

// Uname

type Utsname C.struct_utsname
Expand Down
11 changes: 11 additions & 0 deletions unix/zsyscall_openbsd_386.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions unix/zsyscall_openbsd_amd64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions unix/zsyscall_openbsd_arm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions unix/ztypes_openbsd_386.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions unix/ztypes_openbsd_amd64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions unix/ztypes_openbsd_arm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 44b849a

Please sign in to comment.