diff --git a/mktypes.bash b/mktypes.bash index 0c07680..82ee167 100755 --- a/mktypes.bash +++ b/mktypes.bash @@ -13,7 +13,7 @@ GODEFS="go tool cgo -godefs" $GODEFS types.go |gofmt > ztypes_$GOARCH.go case $GOOS in -freebsd|dragonfly) +freebsd|dragonfly|openbsd) $GODEFS types_$GOOS.go |gofmt > ztypes_$GOOSARCH.go ;; esac diff --git a/pty_openbsd.go b/pty_openbsd.go new file mode 100644 index 0000000..6e7aeae --- /dev/null +++ b/pty_openbsd.go @@ -0,0 +1,33 @@ +package pty + +import ( + "os" + "syscall" + "unsafe" +) + +func open() (pty, tty *os.File, err error) { + /* + * from ptm(4): + * The PTMGET command allocates a free pseudo terminal, changes its + * ownership to the caller, revokes the access privileges for all previous + * users, opens the file descriptors for the master and slave devices and + * returns them to the caller in struct ptmget. + */ + + p, err := os.OpenFile("/dev/ptm", os.O_RDWR|syscall.O_CLOEXEC, 0) + if err != nil { + return nil, nil, err + } + defer p.Close() + + var ptm ptmget + if err := ioctl(p.Fd(), uintptr(ioctl_PTMGET), uintptr(unsafe.Pointer(&ptm))); err != nil { + return nil, nil, err + } + + pty = os.NewFile(uintptr(ptm.Cfd), "/dev/ptm") + tty = os.NewFile(uintptr(ptm.Sfd), "/dev/ptm") + + return pty, tty, nil +} diff --git a/pty_unsupported.go b/pty_unsupported.go index bd3d1e7..9a3e721 100644 --- a/pty_unsupported.go +++ b/pty_unsupported.go @@ -1,4 +1,4 @@ -// +build !linux,!darwin,!freebsd,!dragonfly +// +build !linux,!darwin,!freebsd,!dragonfly,!openbsd package pty diff --git a/types_openbsd.go b/types_openbsd.go new file mode 100644 index 0000000..47701b5 --- /dev/null +++ b/types_openbsd.go @@ -0,0 +1,14 @@ +// +build ignore + +package pty + +/* +#include +#include +#include +*/ +import "C" + +type ptmget C.struct_ptmget + +var ioctl_PTMGET = C.PTMGET diff --git a/ztypes_openbsd_amd64.go b/ztypes_openbsd_amd64.go new file mode 100644 index 0000000..e670516 --- /dev/null +++ b/ztypes_openbsd_amd64.go @@ -0,0 +1,13 @@ +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs types_openbsd.go + +package pty + +type ptmget struct { + Cfd int32 + Sfd int32 + Cn [16]int8 + Sn [16]int8 +} + +var ioctl_PTMGET = 0x40287401