From 33b62fd1c8130e7e9e8046f3983366d67bb4f408 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Fri, 15 Mar 2024 10:54:18 +0100 Subject: [PATCH] virtio: Simplify setRawMode This uses more helper APIs from github.com/pkg/term/termios, and makes the code closer to Apple's recommendations in https://developer.apple.com/documentation/virtualization/running_linux_in_a_virtual_machine?language=objc#:~:text=Configure%20the%20Serial%20Port%20Device%20for%20Standard%20In%20and%20Out This also removes direct use of `syscall` in pkg/vf/virtio.go Signed-off-by: Christophe Fergeau --- pkg/vf/virtio.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/pkg/vf/virtio.go b/pkg/vf/virtio.go index 34089fa6..b33b38bd 100644 --- a/pkg/vf/virtio.go +++ b/pkg/vf/virtio.go @@ -6,7 +6,6 @@ import ( "os" "path/filepath" "strings" - "syscall" "github.com/crc-org/vfkit/pkg/config" "github.com/onsi/gocleanup" @@ -232,21 +231,19 @@ func unixFd(fd uintptr) int { // https://developer.apple.com/documentation/virtualization/running_linux_in_a_virtual_machine#3880009 func setRawMode(f *os.File) error { // Get settings for terminal - attr, _ := unix.IoctlGetTermios(unixFd(f.Fd()), unix.TIOCGETA) + var attr unix.Termios + err := termios.Tcgetattr(f.Fd(), &attr) + if err != nil { + return err + } // Put stdin into raw mode, disabling local echo, input canonicalization, // and CR-NL mapping. - attr.Iflag &^= syscall.ICRNL - attr.Lflag &^= syscall.ICANON | syscall.ECHO - - // Set minimum characters when reading = 1 char - attr.Cc[syscall.VMIN] = 1 - - // set timeout when reading as non-canonical mode - attr.Cc[syscall.VTIME] = 0 + attr.Iflag &^= unix.ICRNL + attr.Lflag &^= unix.ICANON | unix.ECHO // reflects the changed settings - return unix.IoctlSetTermios(unixFd(f.Fd()), unix.TIOCSETA, attr) + return termios.Tcsetattr(f.Fd(), termios.TCSANOW, &attr) } func (dev *VirtioSerial) toVz() (*vz.VirtioConsoleDeviceSerialPortConfiguration, error) {