times in a row, hang up regardless of the value of errno; this fixes a
problem where nano doesn't terminate properly under xterm if the user
su's to root, runs nano, and then closes the terminal window
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3309
35c25a1d-7b9e-4130-9fde-
d3aeb78583b8
set errno to EINVAL as well as return -1 if they fail. This
matches the manual page. (DLR)
- winio.c:
+ get_key_buffer()
+ - If we fail to get a character over MAX_BUF_SIZE times in a
+ row, hang up regardless of the value of errno. This fixes a
+ problem where nano doesn't terminate properly under xterm if
+ the user su's to root, runs nano, and then closes the terminal
+ window. (DLR, found by John <acocaracha@gmail.com>)
parse_kbinput()
- Interpret Shift-Begin, Shift-Delete, Shift-End, Shift-Home,
Shift-Insert, and Shift-Suspend as Begin, Delete, End, Home,
* counting the blank lines at their ends. */
#define MAX_SEARCH_HISTORY 100
-/* The maximum number of bytes we read into a buffer at one time. */
+/* The maximum number of bytes buffered at one time. */
#define MAX_BUF_SIZE 128
#endif /* !NANO_H */
* default keystroke buffer is empty. */
void get_key_buffer(WINDOW *win)
{
- int input;
+ int input, errcount;
/* If the keystroke buffer isn't empty, get out. */
if (key_buffer != NULL)
* screen updates. */
doupdate();
+ errcount = 0;
while ((input = wgetch(win)) == ERR) {
+ errcount++;
+
/* If errno is EIO, it means that the input source that we were
- * using is gone, so die gracefully. */
- if (errno == EIO)
+ * using is gone, so die gracefully. If we've failed to get a
+ * character over MAX_BUF_SIZE times in a row, it can mean the
+ * same thing regardless of the value of errno, so die
+ * gracefully then too. */
+ if (errno == EIO || errcount > MAX_BUF_SIZE)
handle_hupterm(0);
}