From 4e0013bc61edea7ae6fbd5c40a3a7c32f7b6d883 Mon Sep 17 00:00:00 2001 From: Timo Korvola Date: Thu, 25 Jan 2018 01:46:46 +0200 Subject: [PATCH] Simplify the SIGWINCH handler. 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 | 4 ++++ src/curses/ux_init.c | 10 ++++++---- src/curses/ux_input.c | 4 ++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/curses/ux_frotz.h b/src/curses/ux_frotz.h index dec8f8c..67240c3 100644 --- a/src/curses/ux_frotz.h +++ b/src/curses/ux_frotz.h @@ -5,6 +5,8 @@ * */ +#include + #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 */ diff --git a/src/curses/ux_init.c b/src/curses/ux_init.c index 7daee38..2313575 100644 --- a/src/curses/ux_init.c +++ b/src/curses/ux_init.c @@ -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); } diff --git a/src/curses/ux_input.c b/src/curses/ux_input.c index eb6bdef..70b9b70 100644 --- a/src/curses/ux_input.c +++ b/src/curses/ux_input.c @@ -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(); -- 2.34.1