mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-21 17:38:10 +00:00
rawmode_linux.go only cleared ICANON|ECHO but left ISIG enabled, so the terminal driver caught Ctrl+C and generated SIGINT. signal.Notify caught the SIGINT but no goroutine consumed the channel, effectively swallowing the signal. Fix: also clear ISIG so Ctrl+C is delivered as byte 0x03, which the line editor handles with os.Exit(130). Also set VMIN=1, VTIME=0 for proper blocking read behavior.
26 lines
611 B
Go
26 lines
611 B
Go
//go:build linux
|
|
|
|
package main
|
|
|
|
import (
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
func setRawMode(fd int) (func(), error) {
|
|
var old termios
|
|
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), TCGETS, uintptr(unsafe.Pointer(&old))); err != 0 {
|
|
return func() {}, err
|
|
}
|
|
new := old
|
|
new.Lflag &^= ICANON | ECHO | ISIG
|
|
new.Cc[VMIN] = 1
|
|
new.Cc[VTIME] = 0
|
|
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), TCSETS, uintptr(unsafe.Pointer(&new))); err != 0 {
|
|
return func() {}, err
|
|
}
|
|
return func() {
|
|
syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), TCSETS, uintptr(unsafe.Pointer(&old)))
|
|
}, nil
|
|
}
|