Add safe_refresh() temporarily blocking SIGALRM to avoid
authorMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 6 Apr 2023 09:00:35 +0000 (09:00 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 6 Apr 2023 09:00:35 +0000 (09:00 +0000)
potentially interrupting I/O syscalls.

src/main.cpp
src/main.h [new file with mode: 0644]
src/mishaps.cpp

index 75dd62f..75ddbb9 100644 (file)
@@ -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 (file)
index 0000000..70d68a9
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef __MAIN_H__
+#define __MAIN_H__
+
+void safe_refresh(void);
+
+#endif
index 031afe2..485399c 100644 (file)
@@ -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();
          };
        };
       };