Simplify the SIGWINCH handler.
authorTimo Korvola <tkorvola@iki.fi>
Wed, 24 Jan 2018 23:46:46 +0000 (01:46 +0200)
committerTimo Korvola <tkorvola@iki.fi>
Wed, 24 Jan 2018 23:54:22 +0000 (01:54 +0200)
Calling curses from the signal handler may not be safe.
So just set a flag and do the actual work in unix_read_char.

src/curses/ux_frotz.h
src/curses/ux_init.c
src/curses/ux_input.c

index dec8f8c36e233048ed5602adb0b4339b1d146679..67240c339d3594825fd2ac1528bdf33b85c08a9f 100644 (file)
@@ -5,6 +5,8 @@
  *
  */
 
+#include <signal.h>
+
 #include "defines.h"
 #include "../common/frotz.h"
 #include "../blorb/blorb.h"
@@ -79,6 +81,8 @@ extern char *gamepath;        /* use to find sound files */
 extern f_setup_t f_setup;
 extern u_setup_t u_setup;
 
+extern volatile sig_atomic_t terminal_resized;
+
 /*** Functions specific to the Unix port of Frotz ***/
 
 bool unix_init_pictures(void);         /* ux_pic.c */
index 7daee388c4ecfa1081cfb92660feb7f3c6526871..23135758799463b158335988fa2806cd565ad8de 100644 (file)
@@ -48,6 +48,8 @@
 f_setup_t f_setup;
 u_setup_t u_setup;
 
+volatile sig_atomic_t terminal_resized = 0;
+
 static int getconfig(char *);
 static int geterrmode(char *);
 static int getcolor(char *);
@@ -967,14 +969,14 @@ static int geterrmode(char *value)
  * sigwinch_handler
  *
  * Called whenever Frotz recieves a SIGWINCH signal to make curses
- * cleanly resize the window.
+ * cleanly resize the window.  To be safe, just set a flag here.
+ * It is checked and cleared in unix_read_char.
  *
  */
 static void sigwinch_handler(int UNUSED(sig))
 {
-  signal(SIGWINCH, SIG_IGN);
-  unix_resize_display();
-  signal(SIGWINCH, sigwinch_handler);
+    terminal_resized = 1;
+    signal(SIGWINCH, sigwinch_handler);
 }
 
 
index eb6bdefefa99810f4337dc1257fa0c54079e7b4a..70b9b703657e143e3b65e31718ad47a7412c5273 100644 (file)
@@ -130,6 +130,10 @@ static int unix_read_char(int extkeys)
     int c;
 
     while(1) {
+        while (terminal_resized) {
+            terminal_resized = 0;
+            unix_resize_display();
+        }
        timeout( timeout_to_ms());
        c = getch();