diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-12-19 13:17:13 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-12-19 13:17:13 +0000 |
commit | 3156c2e3bc0d513a4332c7f472fd6b9b31a5094e (patch) | |
tree | 122c5ac4494f743e2613176c9ed5d83daad1d480 /crawl-ref/source/libunix.cc | |
parent | bb1a887fb819272e46b5f593d2a2debf81a802ad (diff) | |
download | crawl-ref-3156c2e3bc0d513a4332c7f472fd6b9b31a5094e.tar.gz crawl-ref-3156c2e3bc0d513a4332c7f472fd6b9b31a5094e.zip |
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
Diffstat (limited to 'crawl-ref/source/libunix.cc')
-rw-r--r-- | crawl-ref/source/libunix.cc | 39 |
1 files changed, 35 insertions, 4 deletions
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 <termios.h> @@ -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(); @@ -210,12 +240,14 @@ 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(); |