Skip to content

Commit 33b62fd

Browse files
cfergeauevidolob
authored andcommitted
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 <[email protected]>
1 parent 1cefce1 commit 33b62fd

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

pkg/vf/virtio.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"os"
77
"path/filepath"
88
"strings"
9-
"syscall"
109

1110
"github.com/crc-org/vfkit/pkg/config"
1211
"github.com/onsi/gocleanup"
@@ -232,21 +231,19 @@ func unixFd(fd uintptr) int {
232231
// https://developer.apple.com/documentation/virtualization/running_linux_in_a_virtual_machine#3880009
233232
func setRawMode(f *os.File) error {
234233
// Get settings for terminal
235-
attr, _ := unix.IoctlGetTermios(unixFd(f.Fd()), unix.TIOCGETA)
234+
var attr unix.Termios
235+
err := termios.Tcgetattr(f.Fd(), &attr)
236+
if err != nil {
237+
return err
238+
}
236239

237240
// Put stdin into raw mode, disabling local echo, input canonicalization,
238241
// and CR-NL mapping.
239-
attr.Iflag &^= syscall.ICRNL
240-
attr.Lflag &^= syscall.ICANON | syscall.ECHO
241-
242-
// Set minimum characters when reading = 1 char
243-
attr.Cc[syscall.VMIN] = 1
244-
245-
// set timeout when reading as non-canonical mode
246-
attr.Cc[syscall.VTIME] = 0
242+
attr.Iflag &^= unix.ICRNL
243+
attr.Lflag &^= unix.ICANON | unix.ECHO
247244

248245
// reflects the changed settings
249-
return unix.IoctlSetTermios(unixFd(f.Fd()), unix.TIOCSETA, attr)
246+
return termios.Tcsetattr(f.Fd(), termios.TCSANOW, &attr)
250247
}
251248

252249
func (dev *VirtioSerial) toVz() (*vz.VirtioConsoleDeviceSerialPortConfiguration, error) {

0 commit comments

Comments
 (0)