From: Matthew Mondor Date: Thu, 6 Apr 2023 09:00:35 +0000 (+0000) Subject: Add safe_refresh() temporarily blocking SIGALRM to avoid X-Git-Url: http://git.pulsar-zone.net/?a=commitdiff_plain;h=8c8f5cdf06971bd76f38141a7a754ccb2c40558a;p=curblaster.git Add safe_refresh() temporarily blocking SIGALRM to avoid potentially interrupting I/O syscalls. --- diff --git a/src/main.cpp b/src/main.cpp index 75dd62f..75ddbb9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -71,6 +71,7 @@ static void sighandler(int); static void cleanup(void); static bool clock_expired = false; +static sigset_t block_mask; static int uc = ERR; @@ -96,6 +97,10 @@ clock_init(void) if (sigaction(SIGHUP, &act, NULL) != 0) err(EXIT_FAILURE, "sigaction(SIGHUP)"); + /* Block mask */ + (void)sigemptyset(&block_mask); + (void)sigaddset(&block_mask, SIGALRM); + /* Setup interval timer */ timerclear(&itv.it_interval); timerclear(&itv.it_value); @@ -164,6 +169,22 @@ stable_getch(void) return c; } +void +safe_refresh(void) +{ + sigset_t set; + + /* Temporarily block the SIGALRM signal during output syscalls */ + set = block_mask; + (void)sigprocmask(SIG_BLOCK, &set, NULL); + + (void)wrefresh(win); + + set = block_mask; + (void)sigprocmask(SIG_UNBLOCK, &set, NULL); +} + + /* * On some systems like OSX [n]curses endwin() is not enough to properly diff --git a/src/main.h b/src/main.h new file mode 100644 index 0000000..70d68a9 --- /dev/null +++ b/src/main.h @@ -0,0 +1,6 @@ +#ifndef __MAIN_H__ +#define __MAIN_H__ + +void safe_refresh(void); + +#endif diff --git a/src/mishaps.cpp b/src/mishaps.cpp index 031afe2..485399c 100644 --- a/src/mishaps.cpp +++ b/src/mishaps.cpp @@ -15,6 +15,7 @@ #endif #include "randmac.h" +#include "main.h" #ifdef __USE_SDL__ game_object encrazify(game_object lander, game_object crazy, Mix_Chunk *sound, int channel){ @@ -63,7 +64,7 @@ int boom_object(int drawlocation, game_object boomstuff, game_object object){ }; //get the cursor out of the way mvprintw(23,79,"-"); - refresh(); + safe_refresh(); }; }; };