]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
gui.c: Reset terminal on shutdown in external mode.
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 5 Mar 2016 20:35:59 +0000 (21:35 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 13 Mar 2016 17:19:00 +0000 (18:19 +0100)
If para_gui receives a terminating signal while an external program
is running, the terminal might be left in an unusable state. This
patch handles this case by first returning to program mode, which
sets the terminal to in-curses state, then calling endwin().

The def_prog_mode() call made no sense here at all.

gui.c

diff --git a/gui.c b/gui.c
index a2d4b5f6c7611914b566128f509bea80caf6fe76..e85edba929780c440aa36915347bbb7fbca74911 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -498,9 +498,18 @@ static __printf_2_3 void curses_log(int ll, const char *fmt,...)
 /** The log function of para_gui, always set to curses_log(). */
 __printf_2_3 void (*para_log)(int, const char*, ...) = curses_log;
 
+/* Call endwin() to reset the terminal into non-visual mode. */
 static void shutdown_curses(void)
 {
-       def_prog_mode();
+       /*
+        * If para_gui received a terminating signal in external mode, the
+        * terminal can be in an unusable state at this point because the child
+        * process might not have caught the signal. In this case endwin() has
+        * already been called and must not be called again. So we first return
+        * to program mode, then call endwin().
+        */
+       if (!curses_active())
+               reset_prog_mode();
        endwin();
 }