1package pty 2 3import ( 4 "os" 5 "syscall" 6 "unsafe" 7) 8 9func 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 master and slave devices and 15 * returns them to the caller in struct ptmget. 16 */ 17 18 p, err := os.OpenFile("/dev/ptm", os.O_RDWR|syscall.O_CLOEXEC, 0) 19 if err != nil { 20 return nil, nil, err 21 } 22 defer p.Close() 23 24 var ptm ptmget 25 if err := ioctl(p.Fd(), uintptr(ioctl_PTMGET), uintptr(unsafe.Pointer(&ptm))); err != nil { 26 return nil, nil, err 27 } 28 29 pty = os.NewFile(uintptr(ptm.Cfd), "/dev/ptm") 30 tty = os.NewFile(uintptr(ptm.Sfd), "/dev/ptm") 31 32 return pty, tty, nil 33} 34