pty_openbsd.go 811 B

123456789101112131415161718192021222324252627282930313233343536
  1. //go:build openbsd
  2. // +build openbsd
  3. package pty
  4. import (
  5. "os"
  6. "syscall"
  7. "unsafe"
  8. )
  9. func open() (pty, tty *os.File, err error) {
  10. /*
  11. * from ptm(4):
  12. * The PTMGET command allocates a free pseudo terminal, changes its
  13. * ownership to the caller, revokes the access privileges for all previous
  14. * users, opens the file descriptors for the pty and tty devices and
  15. * returns them to the caller in struct ptmget.
  16. */
  17. p, err := os.OpenFile("/dev/ptm", os.O_RDWR|syscall.O_CLOEXEC, 0)
  18. if err != nil {
  19. return nil, nil, err
  20. }
  21. defer p.Close()
  22. var ptm ptmget
  23. if err := ioctl(p.Fd(), uintptr(ioctl_PTMGET), uintptr(unsafe.Pointer(&ptm))); err != nil {
  24. return nil, nil, err
  25. }
  26. pty = os.NewFile(uintptr(ptm.Cfd), "/dev/ptm")
  27. tty = os.NewFile(uintptr(ptm.Sfd), "/dev/ptm")
  28. return pty, tty, nil
  29. }