[lxc-devel] [lxd/master] termios: Workaround vet on go tip

stgraber on Github lxc-bot at linuxcontainers.org
Sat Jan 27 03:57:16 UTC 2018


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/20180127/2c8451b1/attachment.bin>
-------------- next part --------------
From 8f02215ae6f1dbc9f184a833796763bb65a4c6f8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 26 Jan 2018 22:56:46 -0500
Subject: [PATCH] termios: Workaround vet on go tip
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.go      | 84 -----------------------------------------
 shared/termios/termios_unix.go | 85 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 84 deletions(-)
 create mode 100644 shared/termios/termios_unix.go

diff --git a/shared/termios/termios.go b/shared/termios/termios.go
index 1b841c722..884378cb7 100644
--- a/shared/termios/termios.go
+++ b/shared/termios/termios.go
@@ -1,85 +1 @@
-// +build !windows
-
 package termios
-
-import (
-	"syscall"
-	"unsafe"
-
-	"github.com/lxc/lxd/shared"
-)
-
-// #include <termios.h>
-import "C"
-
-// State contains the state of a terminal.
-type State struct {
-	Termios syscall.Termios
-}
-
-// IsTerminal returns true if the given file descriptor is a terminal.
-func IsTerminal(fd int) bool {
-	_, err := GetState(fd)
-	return err == nil
-}
-
-// 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 := syscall.Termios{}
-
-	ret, err := C.tcgetattr(C.int(fd), (*C.struct_termios)(unsafe.Pointer(&termios)))
-	if ret != 0 {
-		return nil, err.(syscall.Errno)
-	}
-
-	state := State{}
-	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 := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&dimensions)), 0, 0, 0); err != 0 {
-		return -1, -1, err
-	}
-
-	return int(dimensions[1]), int(dimensions[0]), 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.
-func MakeRaw(fd int) (*State, error) {
-	var err error
-	var oldState, newState *State
-
-	oldState, err = GetState(fd)
-	if err != nil {
-		return nil, err
-	}
-
-	err = shared.DeepCopy(&oldState, &newState)
-	if err != nil {
-		return nil, err
-	}
-
-	C.cfmakeraw((*C.struct_termios)(unsafe.Pointer(&newState.Termios)))
-
-	err = Restore(fd, newState)
-	if err != nil {
-		return nil, err
-	}
-
-	return oldState, nil
-}
-
-// Restore restores the terminal connected to the given file descriptor to a previous state.
-func Restore(fd int, state *State) error {
-	ret, err := C.tcsetattr(C.int(fd), C.TCSANOW, (*C.struct_termios)(unsafe.Pointer(&state.Termios)))
-	if ret != 0 {
-		return err.(syscall.Errno)
-	}
-
-	return nil
-}
diff --git a/shared/termios/termios_unix.go b/shared/termios/termios_unix.go
new file mode 100644
index 000000000..1b841c722
--- /dev/null
+++ b/shared/termios/termios_unix.go
@@ -0,0 +1,85 @@
+// +build !windows
+
+package termios
+
+import (
+	"syscall"
+	"unsafe"
+
+	"github.com/lxc/lxd/shared"
+)
+
+// #include <termios.h>
+import "C"
+
+// State contains the state of a terminal.
+type State struct {
+	Termios syscall.Termios
+}
+
+// IsTerminal returns true if the given file descriptor is a terminal.
+func IsTerminal(fd int) bool {
+	_, err := GetState(fd)
+	return err == nil
+}
+
+// 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 := syscall.Termios{}
+
+	ret, err := C.tcgetattr(C.int(fd), (*C.struct_termios)(unsafe.Pointer(&termios)))
+	if ret != 0 {
+		return nil, err.(syscall.Errno)
+	}
+
+	state := State{}
+	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 := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&dimensions)), 0, 0, 0); err != 0 {
+		return -1, -1, err
+	}
+
+	return int(dimensions[1]), int(dimensions[0]), 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.
+func MakeRaw(fd int) (*State, error) {
+	var err error
+	var oldState, newState *State
+
+	oldState, err = GetState(fd)
+	if err != nil {
+		return nil, err
+	}
+
+	err = shared.DeepCopy(&oldState, &newState)
+	if err != nil {
+		return nil, err
+	}
+
+	C.cfmakeraw((*C.struct_termios)(unsafe.Pointer(&newState.Termios)))
+
+	err = Restore(fd, newState)
+	if err != nil {
+		return nil, err
+	}
+
+	return oldState, nil
+}
+
+// Restore restores the terminal connected to the given file descriptor to a previous state.
+func Restore(fd int, state *State) error {
+	ret, err := C.tcsetattr(C.int(fd), C.TCSANOW, (*C.struct_termios)(unsafe.Pointer(&state.Termios)))
+	if ret != 0 {
+		return err.(syscall.Errno)
+	}
+
+	return nil
+}


More information about the lxc-devel mailing list