From 62a7e56d340762d632046d1964fc9f758c73bafb Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 17 Jul 2017 10:36:52 +0200 Subject: [PATCH] [pkg/term] use IoctlGetTermios/IoctlSetTermios from x/sys/unix Use IoctlGetTermios/IoctlSetTermios from golang.org/x/sys/unix instead of manually reimplementing them. Signed-off-by: Tobias Klauser Upstream-commit: 6476504695284fcdc32b5f7621cffca22746e67d Component: engine --- components/engine/pkg/term/termios_linux.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/components/engine/pkg/term/termios_linux.go b/components/engine/pkg/term/termios_linux.go index 31bfa8419e..3e25eb7a41 100644 --- a/components/engine/pkg/term/termios_linux.go +++ b/components/engine/pkg/term/termios_linux.go @@ -1,8 +1,6 @@ package term import ( - "unsafe" - "golang.org/x/sys/unix" ) @@ -18,20 +16,21 @@ type Termios unix.Termios // 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 := unix.Syscall(unix.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 { + termios, err := unix.IoctlGetTermios(int(fd), getTermios) + if err != nil { return nil, err } - newState := oldState.termios + var oldState State + oldState.termios = Termios(*termios) - newState.Iflag &^= (unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON) - newState.Oflag &^= unix.OPOST - newState.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN) - newState.Cflag &^= (unix.CSIZE | unix.PARENB) - newState.Cflag |= unix.CS8 + termios.Iflag &^= (unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON) + termios.Oflag &^= unix.OPOST + termios.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN) + termios.Cflag &^= (unix.CSIZE | unix.PARENB) + termios.Cflag |= unix.CS8 - if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 { + if err := unix.IoctlSetTermios(int(fd), setTermios, termios); err != nil { return nil, err } return &oldState, nil