tc_linux.go 845 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. func ioctl(fd, flag, data uintptr) error {
  13. if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, flag, data); err != 0 {
  14. return err
  15. }
  16. return nil
  17. }
  18. // unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f.
  19. // unlockpt should be called before opening the slave side of a pty.
  20. func unlockpt(f *os.File) error {
  21. var u int32
  22. return ioctl(f.Fd(), unix.TIOCSPTLCK, uintptr(unsafe.Pointer(&u)))
  23. }
  24. // ptsname retrieves the name of the first available pts for the given master.
  25. func ptsname(f *os.File) (string, error) {
  26. n, err := unix.IoctlGetInt(int(f.Fd()), unix.TIOCGPTN)
  27. if err != nil {
  28. return "", err
  29. }
  30. return fmt.Sprintf("/dev/pts/%d", n), nil
  31. }