From 078e90329688224ba54c225e9f81da652d364714 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 3 Jul 2017 14:05:36 +0200 Subject: [PATCH] libcontainer: use ioctl wrappers from x/sys/unix Use IoctlGetInt and IoctlGetTermios/IoctlSetTermios instead of manually reimplementing them. Because of unlockpt, the ioctl wrapper is still needed as it needs to pass a pointer to a value, which is not supported by any ioctl function in x/sys/unix yet. Signed-off-by: Tobias Klauser --- libcontainer/console_linux.go | 12 +++++------- libcontainer/system/linux.go | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/libcontainer/console_linux.go b/libcontainer/console_linux.go index 477b5602e..f70de3848 100644 --- a/libcontainer/console_linux.go +++ b/libcontainer/console_linux.go @@ -123,8 +123,8 @@ func unlockpt(f *os.File) error { // 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 { + n, err := unix.IoctlGetInt(int(f.Fd()), unix.TIOCGPTN) + if err != nil { return "", err } return fmt.Sprintf("/dev/pts/%d", n), nil @@ -136,17 +136,15 @@ func ptsname(f *os.File) (string, error) { // problem for terminal emulators, because we relay data from the terminal we // also relay that funky line discipline. 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 { + termios, err := unix.IoctlGetTermios(int(terminal.Fd()), unix.TCGETS) + if err != nil { 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.IoctlSetTermios(int(terminal.Fd()), unix.TCSETS, termios); err != nil { return fmt.Errorf("ioctl(tty, tcsets): %s", err.Error()) } diff --git a/libcontainer/system/linux.go b/libcontainer/system/linux.go index a173de760..4837085a7 100644 --- a/libcontainer/system/linux.go +++ b/libcontainer/system/linux.go @@ -95,7 +95,7 @@ func ClearKeepCaps() error { } func Setctty() error { - if _, _, err := unix.RawSyscall(unix.SYS_IOCTL, 0, uintptr(unix.TIOCSCTTY), 0); err != 0 { + if err := unix.IoctlSetInt(0, unix.TIOCSCTTY, 0); err != nil { return err } return nil