From 3156c2e3bc0d513a4332c7f472fd6b9b31a5094e Mon Sep 17 00:00:00 2001 From: dshaligram Date: Tue, 19 Dec 2006 13:17:13 +0000 Subject: Handle SIGHUP. Could use improvement, but it's a start. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@673 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/libunix.cc | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'crawl-ref/source/libunix.cc') diff --git a/crawl-ref/source/libunix.cc b/crawl-ref/source/libunix.cc index 317ba174d7..a02ffbf7c4 100644 --- a/crawl-ref/source/libunix.cc +++ b/crawl-ref/source/libunix.cc @@ -45,6 +45,7 @@ #include "enum.h" #include "externs.h" +#include "files.h" #include @@ -198,6 +199,35 @@ int getch_ck() { } } +#if defined(USE_UNIX_SIGNALS) && defined(SIGHUP_SAVE) + +/* [ds] This SIGHUP handling is primitive and far from safe, but it + * should be better than nothing. Feel free to get rigorous on this. + */ +static void handle_hangup(int) +{ + if (crawl_state.seen_hups++) + return; + + if (crawl_state.saving_game || crawl_state.updating_scores) + return; + + crawl_state.saving_game = true; + if (crawl_state.need_save) + { + // save_game(true) also exits, saving us the trouble of doing so. + save_game(true); + } + else + { + // CROAK! No attempt to clean up curses. This is probably not an + // issue since the term has gone away. + exit(1); + } +} + +#endif // USE_UNIX_SIGNALS && SIGHUP_SAVE + void unixcurses_startup( void ) { termio_init(); @@ -209,13 +239,15 @@ void unixcurses_startup( void ) #ifdef SIGINT signal(SIGINT, SIG_IGN); -#endif #endif - //savetty(); +#ifdef SIGHUP_SAVE + signal(SIGHUP, handle_hangup); +#endif + +#endif initscr(); - // cbreak(); raw(); noecho(); @@ -228,7 +260,6 @@ void unixcurses_startup( void ) ESCDELAY = CURSES_SET_ESCDELAY; #endif #endif - //cbreak(); meta(stdscr, TRUE); start_color(); -- cgit v1.2.3-54-g00ecf