pty_openbsd.go 773 B

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