diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c index 61523d9d..ac166f2d 100644 --- a/src/fe-text/gui-readline.c +++ b/src/fe-text/gui-readline.c @@ -331,6 +331,12 @@ void readline(void) int ret, i; ret = term_gets(buffer, sizeof(buffer)); + if (ret == -1) { + /* lost terminal */ + signal_emit("command quit", 1, "Lost terminal"); + return; + } + for (i = 0; i < ret; i++) handle_key(buffer[i]); } diff --git a/src/fe-text/term-terminfo.c b/src/fe-text/term-terminfo.c index 85ac193b..88296131 100644 --- a/src/fe-text/term-terminfo.c +++ b/src/fe-text/term-terminfo.c @@ -328,6 +328,14 @@ void term_stop(void) int term_gets(unsigned char *buffer, int size) { + int ret; + /* fread() doesn't work */ - return read(fileno(current_term->in), buffer, size); + ret = read(fileno(current_term->in), buffer, size); + if (ret == 0) + ret = -1;/* EOF - terminal got lost */ + else if (ret == -1 && (errno == EINTR || errno == EAGAIN)) + ret = 0; + + return ret; }