From 31a1003a84ec2d5825adb45cfb86058638e4879f Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 7 Feb 2014 00:44:14 +0000 Subject: [PATCH 1/2] Add Freebsd client support Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes (github: creack) --- term/termios_bsd.go | 67 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 term/termios_bsd.go diff --git a/term/termios_bsd.go b/term/termios_bsd.go new file mode 100644 index 0000000..9acf9df --- /dev/null +++ b/term/termios_bsd.go @@ -0,0 +1,67 @@ +package term + +import ( + "syscall" + "unsafe" +) + +const ( + getTermios = syscall.TIOCGETA + setTermios = syscall.TIOCSETA + + IGNBRK = syscall.IGNBRK + PARMRK = syscall.PARMRK + INLCR = syscall.INLCR + IGNCR = syscall.IGNCR + ECHONL = syscall.ECHONL + CSIZE = syscall.CSIZE + ICRNL = syscall.ICRNL + ISTRIP = syscall.ISTRIP + PARENB = syscall.PARENB + ECHO = syscall.ECHO + ICANON = syscall.ICANON + ISIG = syscall.ISIG + IXON = syscall.IXON + BRKINT = syscall.BRKINT + INPCK = syscall.INPCK + OPOST = syscall.OPOST + CS8 = syscall.CS8 + IEXTEN = syscall.IEXTEN +) + +type Termios struct { + Iflag uint32 + Oflag uint32 + Cflag uint32 + Lflag uint32 + Cc [20]byte + Ispeed uint32 + Ospeed uint32 +} + +// MakeRaw put the terminal connected to the given file descriptor into raw +// mode and returns the previous state of the terminal so that it can be +// restored. +func MakeRaw(fd uintptr) (*State, error) { + var oldState State + if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 { + return nil, err + } + // C.makeraw() + // return &oldState, nil + + newState := oldState.termios + newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON) + newState.Oflag &^= OPOST + newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN) + newState.Cflag &^= (CSIZE | PARENB) + newState.Cflag |= CS8 + newState.Cc[syscall.VMIN] = 1 + newState.Cc[syscall.VTIME] = 0 + + if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 { + return nil, err + } + + return &oldState, nil +} From 10ae745ed89c254bb95022ef1f5699e91913ec85 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 10 Mar 2014 13:25:00 -0700 Subject: [PATCH 2/2] Update bsd specs Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes (github: creack) --- term/{termios_bsd.go => termios_freebsd.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename term/{termios_bsd.go => termios_freebsd.go} (100%) diff --git a/term/termios_bsd.go b/term/termios_freebsd.go similarity index 100% rename from term/termios_bsd.go rename to term/termios_freebsd.go