#214 Better signal handling

This commit is contained in:
Guillaume J. Charmes 2013-03-27 23:54:53 -07:00
parent 7e9975d00a
commit 108acc0511
2 changed files with 11 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import (
"io" "io"
"log" "log"
"os" "os"
"os/signal"
) )
func main() { func main() {
@ -53,6 +54,15 @@ func runCommand(args []string) error {
return err return err
} }
defer term.Restore(0, oldState) defer term.Restore(0, oldState)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for _ = range c {
term.Restore(0, oldState)
log.Printf("\nSIGINT received\n")
os.Exit(0)
}
}()
} }
// FIXME: we want to use unix sockets here, but net.UnixConn doesn't expose // FIXME: we want to use unix sockets here, but net.UnixConn doesn't expose
// CloseWrite(), which we need to cleanly signal that stdin is closed without // CloseWrite(), which we need to cleanly signal that stdin is closed without

View File

@ -15,7 +15,7 @@ void MakeRaw(int fd) {
ioctl(fd, TCGETS, &t); ioctl(fd, TCGETS, &t);
t.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); t.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
t.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); t.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
t.c_cflag &= ~(CSIZE | PARENB); t.c_cflag &= ~(CSIZE | PARENB);
t.c_cflag |= CS8; t.c_cflag |= CS8;