From c93fe773d8ca6420c4721cd988596601979186c9 Mon Sep 17 00:00:00 2001
From: Andreas Mohr <and@gmx.li>
Date: Fri, 25 Dec 2015 17:31:15 +0000
Subject: [PATCH] fix #2244 infinite loop when stdin fd got deleted
under slang mc check getch() for error condition but not under ncurses yet
test case reported by ginggs:
compile mc --with-screen=ncurses (does not occur with slang)
subshell must be enabled and a suitable shell available (does not occur with busybox)
open a GUI terminal (gnome-terminal, xterminal, konsole is also mentioned)
start mc as root (sudo mc)
close GUI terminal
Signed-off-by: Andreas Mohr <and@gmx.li>
---
lib/tty/tty-ncurses.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/lib/tty/tty-ncurses.c b/lib/tty/tty-ncurses.c
index 83e6fe6..24eae0a 100644
a
|
b
|
|
31 | 31 | |
32 | 32 | #include <config.h> |
33 | 33 | |
| 34 | #include <errno.h> |
34 | 35 | #include <stdlib.h> |
35 | 36 | #include <stdarg.h> |
36 | 37 | #include <signal.h> |
… |
… |
|
83 | 84 | /* We use our own cursor coordibates to support partially visible widgets */ |
84 | 85 | static int mc_curs_row, mc_curs_col; |
85 | 86 | |
| 87 | /* Controls error condition in tty_lowlevel_getch */ |
| 88 | static gboolean no_ncurses_delay; |
| 89 | |
86 | 90 | /*** file scope functions ************************************************************************/ |
87 | 91 | /* --------------------------------------------------------------------------------------------- */ |
88 | 92 | |
… |
… |
tty_keypad (gboolean set) |
326 | 330 | void |
327 | 331 | tty_nodelay (gboolean set) |
328 | 332 | { |
| 333 | no_ncurses_delay = set; |
329 | 334 | nodelay (stdscr, (bool) set); |
330 | 335 | } |
331 | 336 | |
… |
… |
tty_baudrate (void) |
342 | 347 | int |
343 | 348 | tty_lowlevel_getch (void) |
344 | 349 | { |
345 | | return getch (); |
| 350 | int c; |
| 351 | while ((c = getch()) == ERR) |
| 352 | { |
| 353 | /* in no-delay mode getch() returns ERR if no input waiting */ |
| 354 | if (no_ncurses_delay && errno == 0) |
| 355 | return -1; |
| 356 | if (errno == EINTR) |
| 357 | continue; |
| 358 | fprintf (stderr, |
| 359 | "ncurses getch() returned ERR\n" |
| 360 | "Assuming EOF on stdin and exiting\n"); |
| 361 | exit (EXIT_FAILURE); |
| 362 | } |
| 363 | return c; |
346 | 364 | } |
347 | 365 | |
348 | 366 | /* --------------------------------------------------------------------------------------------- */ |