tc_linux.go 820 B

123456789101112131415161718192021222324252627282930313233
  1. package console
  2. import (
  3. "fmt"
  4. "os"
  5. "unsafe"
  6. "golang.org/x/sys/unix"
  7. )
  8. const (
  9. cmdTcGet = unix.TCGETS
  10. cmdTcSet = unix.TCSETS
  11. )
  12. // unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f.
  13. // unlockpt should be called before opening the slave side of a pty.
  14. func unlockpt(f *os.File) error {
  15. var u int32
  16. if _, _, err := unix.Syscall(unix.SYS_IOCTL, f.Fd(), unix.TIOCSPTLCK, uintptr(unsafe.Pointer(&u))); err != 0 {
  17. return err
  18. }
  19. return nil
  20. }
  21. // ptsname retrieves the name of the first available pts for the given master.
  22. func ptsname(f *os.File) (string, error) {
  23. var u uint32
  24. if _, _, err := unix.Syscall(unix.SYS_IOCTL, f.Fd(), unix.TIOCGPTN, uintptr(unsafe.Pointer(&u))); err != 0 {
  25. return "", err
  26. }
  27. return fmt.Sprintf("/dev/pts/%d", u), nil
  28. }