From cb3110778ff7ef6484cbf5b96984e3ea8f06780c Mon Sep 17 00:00:00 2001 From: Alice Frosi Date: Fri, 26 Oct 2018 12:25:52 +0200 Subject: [PATCH] cli: Fix console for big endian architecture The function ioctl can lead to a big endian bug. Issue already solved in containerd/console: https://github.com/containerd/console/pull/20/commits/dbd69c59b81ec72258da35a335605e4b3ea17e6a Fixes: #921 Signed-off-by: Alice Frosi --- cli/console.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/cli/console.go b/cli/console.go index eb1e4758a4..c1555c9f4b 100644 --- a/cli/console.go +++ b/cli/console.go @@ -91,27 +91,23 @@ func (c *Console) Close() error { return nil } -func ioctl(fd uintptr, flag, data uintptr) error { - if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, flag, data); err != 0 { - return err - } - return nil -} - // unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f. // unlockpt should be called before opening the slave side of a pty. func unlockpt(f *os.File) error { var u int32 - return ioctl(f.Fd(), unix.TIOCSPTLCK, uintptr(unsafe.Pointer(&u))) + if _, _, err := unix.Syscall(unix.SYS_IOCTL, f.Fd(), unix.TIOCSPTLCK, uintptr(unsafe.Pointer(&u))); err != 0 { + return err + } + return nil } // ptsname retrieves the name of the first available pts for the given master. func ptsname(f *os.File) (string, error) { - var n int32 - if err := ioctl(f.Fd(), unix.TIOCGPTN, uintptr(unsafe.Pointer(&n))); err != nil { + var u uint32 + if _, _, err := unix.Syscall(unix.SYS_IOCTL, f.Fd(), unix.TIOCGPTN, uintptr(unsafe.Pointer(&u))); err != 0 { return "", err } - return fmt.Sprintf("/dev/pts/%d", n), nil + return fmt.Sprintf("/dev/pts/%d", u), nil } // saneTerminal sets the necessary tty_ioctl(4)s to ensure that a pty pair @@ -123,14 +119,14 @@ func saneTerminal(terminal *os.File) error { // Go doesn't have a wrapper for any of the termios ioctls. var termios unix.Termios - if err := ioctl(terminal.Fd(), unix.TCGETS, uintptr(unsafe.Pointer(&termios))); err != nil { + if _, _, err := unix.Syscall(unix.SYS_IOCTL, terminal.Fd(), unix.TCGETS, uintptr(unsafe.Pointer(&termios))); err != 0 { return fmt.Errorf("ioctl(tty, tcgets): %s", err.Error()) } // Set -onlcr so we don't have to deal with \r. termios.Oflag &^= unix.ONLCR - if err := ioctl(terminal.Fd(), unix.TCSETS, uintptr(unsafe.Pointer(&termios))); err != nil { + if _, _, err := unix.Syscall(unix.SYS_IOCTL, terminal.Fd(), unix.TCSETS, uintptr(unsafe.Pointer(&termios))); err != 0 { return fmt.Errorf("ioctl(tty, tcsets): %s", err.Error()) }