[lxc-devel] [lxd/master] shared/termios: Fix port to sys/unix

stgraber on Github lxc-bot at linuxcontainers.org
Fri Jun 21 04:16:19 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190620/1dce5235/attachment.bin>
-------------- next part --------------
From cc8bafc89e2ea7ccdc92e16dc976c55761fa63bb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 21 Jun 2019 00:15:16 -0400
Subject: [PATCH] shared/termios: Fix port to sys/unix
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 shared/termios/termios_unix.go | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/shared/termios/termios_unix.go b/shared/termios/termios_unix.go
index 375893685f..7802030f8d 100644
--- a/shared/termios/termios_unix.go
+++ b/shared/termios/termios_unix.go
@@ -27,28 +27,25 @@ func IsTerminal(fd int) bool {
 
 // GetState returns the current state of a terminal which may be useful to restore the terminal after a signal.
 func GetState(fd int) (*State, error) {
-	termios := unix.Termios{}
-
-	ret, err := C.tcgetattr(C.int(fd), (*C.struct_termios)(unsafe.Pointer(&termios)))
-	if ret != 0 {
-		return nil, err.(unix.Errno)
+	termios, err := unix.IoctlGetTermios(fd, unix.TCGETS)
+	if err != nil {
+		return nil, err
 	}
 
 	state := State{}
-	state.Termios = termios
+	state.Termios = *termios
 
 	return &state, nil
 }
 
 // GetSize returns the dimensions of the given terminal.
 func GetSize(fd int) (int, int, error) {
-	var dimensions [4]uint16
-
-	if _, _, err := unix.Syscall6(unix.SYS_IOCTL, uintptr(fd), uintptr(unix.TIOCGWINSZ), uintptr(unsafe.Pointer(&dimensions)), 0, 0, 0); err != 0 {
+	winsize, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ)
+	if err != nil {
 		return -1, -1, err
 	}
 
-	return int(dimensions[1]), int(dimensions[0]), nil
+	return int(winsize.Col), int(winsize.Row), nil
 }
 
 // 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.


More information about the lxc-devel mailing list