]> granicus.if.org Git - nethack/commitdiff
X11_hangup()
authorPatR <rankin@nethack.org>
Fri, 10 Feb 2023 23:19:13 +0000 (15:19 -0800)
committerPatR <rankin@nethack.org>
Fri, 10 Feb 2023 23:19:13 +0000 (15:19 -0800)
I was looking at backporting an X11 build fix to 3.6 and decided
that the hangup handling wasn't correct if SAFERHANGUP is defined
(which it is by default).  It didn't attempt to perform a hangup
save.  Also, the handler might return when the X code calling it
expected it to not do so.

I don't know how to force a hangup within X11 so haven't tested
this properly.  It works fine when there's no hangup.  :-/

src/cmd.c
win/X11/winX.c

index df96c79ff84b3ab464abbf817b544b615deaf163..3f47719eadac049ee5b9205c2ba26d4e3c863518 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -6317,7 +6317,8 @@ hangup(
        must continue running longer before attempting a hangup save. */
     gp.program_state.done_hup++;
     /* defer hangup iff game appears to be in progress */
-    if (gp.program_state.in_moveloop && gp.program_state.something_worth_saving)
+    if (gp.program_state.in_moveloop
+        && gp.program_state.something_worth_saving)
         return;
 #endif /* SAFERHANGUP */
     end_of_input();
index 05d7c2ef9b222c8572eed52354555cbe1b94764d..9ee92a123a72db522b3283cb3ccf2564722f0216 100644 (file)
@@ -1515,8 +1515,11 @@ X11_error_handler(String str)
 {
     nhUse(str);
     hangup(1);
-    nh_terminate(EXIT_FAILURE);
+#ifdef SAFERHANGUP /* keeps going after hangup() for '#if SAFERHANGUP' */
+    end_of_input();
+#endif
     /*NOTREACHED*/
+    nh_terminate(EXIT_FAILURE);
 }
 
 static int
@@ -1524,6 +1527,10 @@ X11_io_error_handler(Display *display)
 {
     nhUse(display);
     hangup(1);
+#ifdef SAFERHANGUP /* keeps going after hangup() for '#if SAFERHANGUP' */
+    end_of_input();
+#endif
+    /*NOREACHED*/ /* but not declared NORETURN */
     return 0;
 }