]> granicus.if.org Git - nethack/commitdiff
hangup tweaks (trunk only)
authornethack.rankin <nethack.rankin>
Fri, 19 Jan 2007 03:02:05 +0000 (03:02 +0000)
committernethack.rankin <nethack.rankin>
Fri, 19 Jan 2007 03:02:05 +0000 (03:02 +0000)
     Fix a typo in some conditional (NOSAVEONHANGUP) code, and tweak
SAFERHANGUP so that it doesn't defer hangup handling if the game hasn't
started yet or has already finished (it's possible to be waiting for a
--More-- prompt at end of game code before the hangup handler is reset,
so the regular handler could be called in that state).  Also, undefine
SAFERHANGUP if NOSAVEONHANGUP is defined, since there's no point in
deferring hangup for the latter.

include/global.h
src/cmd.c

index f98c53936948b9b68caa810fe9a2acfe8958f0e4..24d94b74f103d57fae3e2b75cdd8b2ef82ed611d 100644 (file)
@@ -272,7 +272,7 @@ typedef char nhptext;
 #if defined(UNIX) || defined(VMS) || defined(__EMX__) || defined(WIN32)
 # define HANGUPHANDLING
 #endif
-#if defined(SAFERHANGUP) && !defined(HANGUPHANDLING)
+#if defined(SAFERHANGUP) && (defined(NOSAVEONHANGUP) || !defined(HANGUPHANDLING))
 # undef SAFERHANGUP
 #endif
 
index 9d6f43f990002b11fb63be597218489754ed37e3..e123aeb86b0c3e5f08bc81221bd6df0cdd54f4a5 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -2798,6 +2798,9 @@ parse()
 }
 
 #ifdef HANGUPHANDLING
+/* some very old systems, or descendents of such systems, expect signal
+   handlers to have return type `int', but they don't actually inspect
+   the return value so we should be safe using `void' unconditionally */
 /*ARGUSED*/
 void
 hangup(sig_unused) /* called as signal() handler, so sent at least one arg */
@@ -2812,16 +2815,17 @@ int sig_unused;
           but also potentially riskier because the disconnected program
           must continue running longer before attempting a hangup save. */
        program_state.done_hup++;
-# else
+       /* defer hangup iff game appears to be in progress */
+       if (program_state.something_worth_saving) return;
+# endif /* SAFERHANGUP */
        end_of_input();
-# endif /* ?SAFERHANGUP */
 }
 
 void
 end_of_input()
 {
 # ifdef NOSAVEONHANGUP
-       program_state_something_worth_saving = 0;
+       program_state.something_worth_saving = 0;
 # endif
 # ifndef SAFERHANGUP
        if (!program_state.done_hup++)