From 1d30b8582daad60c10834d7e15283d7a74783cbb Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Sat, 25 Apr 2020 18:42:18 -0700 Subject: [PATCH] Fixes for build constraints, MakeRaw()/ReadPassword() etc. fd arg type Signed-off-by: Russ Magee --- go.sum | 2 ++ termmode_linux.go | 22 +++++++++++----------- termmode_windows.go | 2 +- xs/termsize_unix.go | 1 + 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/go.sum b/go.sum index 1b8821e..1852007 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ blitter.com/go/goutmp v1.0.1 h1:jBqtp6pDwSbF4QEC3DjNfyaS8Nv5dFCOyaTfSbbb7TU= blitter.com/go/goutmp v1.0.1/go.mod h1:gtlbjC8xGzMk/Cf0BpnVltSa3awOqJ+B5WAxVptTMxk= blitter.com/go/goutmp v1.0.2 h1:oCc/dt9TlTOP2kvmX1Y7J/wSQUhywjcyF101jXuLxZ8= blitter.com/go/goutmp v1.0.2/go.mod h1:gtlbjC8xGzMk/Cf0BpnVltSa3awOqJ+B5WAxVptTMxk= +blitter.com/go/goutmp v1.0.3 h1:4VPU9COXG36W5454pcV65FieVaaw64mdhvjuTVOuWTM= +blitter.com/go/goutmp v1.0.3/go.mod h1:gtlbjC8xGzMk/Cf0BpnVltSa3awOqJ+B5WAxVptTMxk= blitter.com/go/herradurakex v1.0.0 h1:6XaxY+JLT1HUWPF0gYJnjX3pVjrw4YhYZEzZ1U0wkyc= blitter.com/go/herradurakex v1.0.0/go.mod h1:m3+vYZX+2dDjdo+n/HDnXEYJX9pwmNeQLgAfJM8mtxw= blitter.com/go/kyber v0.0.0-20200130200857-6f2021cb88d9 h1:D45AnrNphtvczBXRp5JQicZRTgaK/Is5bgPDDvRKhTc= diff --git a/termmode_linux.go b/termmode_linux.go index 84538f9..466742b 100644 --- a/termmode_linux.go +++ b/termmode_linux.go @@ -30,8 +30,8 @@ type State struct { // 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) { - termios, err := unix.IoctlGetTermios(fd, ioctlReadTermios) +func MakeRaw(fd uintptr) (*State, error) { + termios, err := unix.IoctlGetTermios(int(fd), ioctlReadTermios) if err != nil { return nil, err } @@ -47,7 +47,7 @@ func MakeRaw(fd int) (*State, error) { termios.Cflag |= unix.CS8 termios.Cc[unix.VMIN] = 1 termios.Cc[unix.VTIME] = 0 - if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, termios); err != nil { + if err := unix.IoctlSetTermios(int(fd), ioctlWriteTermios, termios); err != nil { return nil, err } @@ -56,8 +56,8 @@ func MakeRaw(fd int) (*State, error) { // 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, err := unix.IoctlGetTermios(fd, ioctlReadTermios) +func GetState(fd uintptr) (*State, error) { + termios, err := unix.IoctlGetTermios(int(fd), ioctlReadTermios) if err != nil { return nil, err } @@ -67,9 +67,9 @@ func GetState(fd int) (*State, error) { // Restore restores the terminal connected to the given file descriptor to a // previous state. -func Restore(fd int, state *State) error { +func Restore(fd uintptr, state *State) error { if state != nil { - return unix.IoctlSetTermios(fd, ioctlWriteTermios, &state.termios) + return unix.IoctlSetTermios(int(fd), ioctlWriteTermios, &state.termios) } else { return errors.New("nil State") } @@ -78,8 +78,8 @@ func Restore(fd int, state *State) error { // ReadPassword reads a line of input from a terminal without local echo. This // is commonly used for inputting passwords and other sensitive data. The slice // returned does not include the \n. -func ReadPassword(fd int) ([]byte, error) { - termios, err := unix.IoctlGetTermios(fd, ioctlReadTermios) +func ReadPassword(fd uintptr) ([]byte, error) { + termios, err := unix.IoctlGetTermios(int(fd), ioctlReadTermios) if err != nil { return nil, err } @@ -88,12 +88,12 @@ func ReadPassword(fd int) ([]byte, error) { newState.Lflag &^= unix.ECHO newState.Lflag |= unix.ICANON | unix.ISIG newState.Iflag |= unix.ICRNL - if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, &newState); err != nil { + if err := unix.IoctlSetTermios(int(fd), ioctlWriteTermios, &newState); err != nil { return nil, err } defer func() { - _ = unix.IoctlSetTermios(fd, ioctlWriteTermios, termios) // nolint: gosec + _ = unix.IoctlSetTermios(int(fd), ioctlWriteTermios, termios) // nolint: gosec }() return readPasswordLine(passwordReader(fd)) diff --git a/termmode_windows.go b/termmode_windows.go index 1df01fe..92ec2c3 100644 --- a/termmode_windows.go +++ b/termmode_windows.go @@ -1,5 +1,5 @@ // +build windows -// + // Note the terminal manipulation functions herein are mostly stubs. They // don't really do anything and the xs demo client depends on a wrapper // script using the 'stty' tool to actually set the proper mode for diff --git a/xs/termsize_unix.go b/xs/termsize_unix.go index 122b92e..410a243 100644 --- a/xs/termsize_unix.go +++ b/xs/termsize_unix.go @@ -1,4 +1,5 @@ // +build linux freebsd + package main import (