commit 91493254000520634be208201398d312a8635c83
parent 1ec74ee30c391ab79cfd9a067f37093243c11ce0
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Sun, 19 Mar 2006 19:25:29 +0000
in 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
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3309 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
3 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -58,6 +58,12 @@ CVS code -
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,
diff --git a/src/nano.h b/src/nano.h
@@ -590,7 +590,7 @@ typedef struct rcoption {
* 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 */
diff --git a/src/winio.c b/src/winio.c
@@ -122,7 +122,7 @@ void reset_kbinput(void)
* 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)
@@ -137,10 +137,16 @@ void get_key_buffer(WINDOW *win)
* 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);
}