vm/vmimpl: update console code for the new unix package

The current code is now broken on darwin:

syzkaller$ GOOS=darwin go install ./vm/...
vm/vmimpl/console.go:30:33: undefined: unix.SYS_IOCTL
vm/vmimpl/console.go:45:32: undefined: unix.SYS_IOCTL
This commit is contained in:
Dmitry Vyukov 2020-09-15 19:11:49 +02:00
parent a2267789b8
commit 18d7d030e5

View File

@ -9,7 +9,6 @@ import (
"os/exec"
"sync"
"syscall"
"unsafe"
"github.com/google/syzkaller/pkg/osutil"
"golang.org/x/sys/unix"
@ -26,10 +25,9 @@ func OpenConsole(con string) (rc io.ReadCloser, err error) {
syscall.Close(fd)
}
}()
var term unix.Termios
_, _, errno := syscall.Syscall(unix.SYS_IOCTL, uintptr(fd), syscallTCGETS, uintptr(unsafe.Pointer(&term)))
if errno != 0 {
return nil, fmt.Errorf("failed to get console termios: %v", errno)
term, err := unix.IoctlGetTermios(fd, syscallTCGETS)
if err != nil {
return nil, fmt.Errorf("failed to get console termios: %v", err)
}
// No parity bit, only need 1 stop bit, no hardware flowcontrol,
term.Cflag &^= unixCBAUD | unix.CSIZE | unix.PARENB | unix.CSTOPB | unixCRTSCTS
@ -42,9 +40,8 @@ func OpenConsole(con string) (rc io.ReadCloser, err error) {
term.Oflag &^= unix.OPOST
term.Cc[unix.VMIN] = 0
term.Cc[unix.VTIME] = 10 // 1 second timeout
_, _, errno = syscall.Syscall(unix.SYS_IOCTL, uintptr(fd), syscallTCSETS, uintptr(unsafe.Pointer(&term)))
if errno != 0 {
return nil, fmt.Errorf("failed to get console termios: %v", errno)
if err = unix.IoctlSetTermios(fd, syscallTCSETS, term); err != nil {
return nil, fmt.Errorf("failed to get console termios: %v", err)
}
tmp := fd
fd = -1