diff urogue/mdport.c @ 272:1db299e868b8

UltraRogue: add the autosave feature. UltraRogue now automatically saves the game when SIGHUP or SIGTERM is received.
author John "Elwin" Edwards
date Sun, 03 Sep 2017 19:58:22 -0400
parents 7a96fede6cc8
children 51ddbe7b992d
line wrap: on
line diff
--- a/urogue/mdport.c	Sun Mar 05 20:14:11 2017 -0500
+++ b/urogue/mdport.c	Sun Sep 03 19:58:22 2017 -0400
@@ -1271,3 +1271,43 @@
 
     return(ch & 0x7F);
 }
+
+extern void auto_save(int sig);
+extern void fatal_handler(int sig);
+extern void quit_handler(int sig);
+
+void
+md_onsignal_autosave(void)
+{
+#ifdef SIGHUP
+    signal(SIGHUP, auto_save);
+#endif
+#ifdef SIGQUIT
+    signal(SIGQUIT, fatal_handler);
+#endif
+#ifdef SIGTERM
+    signal(SIGTERM, auto_save);
+#endif
+#ifdef SIGINT
+    signal(SIGINT, quit_handler);
+#endif
+    return;
+}
+
+void
+md_ignore_signals(void)
+{
+#ifdef SIGHUP
+    signal(SIGHUP, SIG_IGN);
+#endif
+#ifdef SIGQUIT
+    signal(SIGQUIT, SIG_IGN);
+#endif
+#ifdef SIGTERM
+    signal(SIGTERM, SIG_IGN);
+#endif
+#ifdef SIGINT
+    signal(SIGINT, SIG_IGN);
+#endif
+    return;
+}