fix remaining contrived issues re HANGUPHANDLING

This commit is contained in:
nhmall
2023-03-01 12:01:43 -05:00
parent 77f241581c
commit 76e82d1312
9 changed files with 54 additions and 12 deletions
+4
View File
@@ -1730,7 +1730,11 @@ static int lockfd = -1; /* for lock_file() to pass to unlock_file() */
struct flock sflock; /* for unlocking, same as above */ struct flock sflock; /* for unlocking, same as above */
#endif #endif
#if defined(HANGUPHANDLING)
#define HUP if (!gp.program_state.done_hup) #define HUP if (!gp.program_state.done_hup)
#else
#define HUP
#endif
#ifndef USE_FCNTL #ifndef USE_FCNTL
static char * static char *
+2 -2
View File
@@ -40,7 +40,7 @@ static void zerocomp_bwrite(int, genericptr_t, unsigned int);
static void zerocomp_bputc(int); static void zerocomp_bputc(int);
#endif #endif
#if defined(UNIX) || defined(VMS) || defined(__EMX__) || defined(WIN32) #if defined(HANGUPHANDLING)
#define HUP if (!gp.program_state.done_hup) #define HUP if (!gp.program_state.done_hup)
#else #else
#define HUP #define HUP
@@ -58,7 +58,7 @@ dosave(void)
} else { } else {
clear_nhwindow(WIN_MESSAGE); clear_nhwindow(WIN_MESSAGE);
pline("Saving..."); pline("Saving...");
#if defined(UNIX) || defined(VMS) || defined(__EMX__) #if defined(HANGUPHANDLING)
gp.program_state.done_hup = 0; gp.program_state.done_hup = 0;
#endif #endif
if (dosave0()) { if (dosave0()) {
+1 -1
View File
@@ -193,7 +193,7 @@ bwrite(int fd, const genericptr_t loc, unsigned num)
#endif #endif
} }
if (failed) { if (failed) {
#if defined(UNIX) || defined(VMS) || defined(__EMX__) #if defined(HANGUPHANDLING)
if (gp.program_state.done_hup) if (gp.program_state.done_hup)
nh_terminate(EXIT_FAILURE); nh_terminate(EXIT_FAILURE);
else else
+1 -1
View File
@@ -644,7 +644,7 @@ topten(int how, time_t when)
gt.toptenwin = create_nhwindow(NHW_TEXT); gt.toptenwin = create_nhwindow(NHW_TEXT);
} }
#if defined(UNIX) || defined(VMS) || defined(__EMX__) #if defined(HANGUPHANDLING)
#define HUP if (!gp.program_state.done_hup) #define HUP if (!gp.program_state.done_hup)
#else #else
#define HUP #define HUP
+4
View File
@@ -164,9 +164,11 @@ main(int argc, char *argv[])
* It seems you really want to play. * It seems you really want to play.
*/ */
u.uhp = 1; /* prevent RIP on early quits */ u.uhp = 1; /* prevent RIP on early quits */
#if defined(HANGUPHANDLING)
gp.program_state.preserve_locks = 1; gp.program_state.preserve_locks = 1;
#ifndef NO_SIGNAL #ifndef NO_SIGNAL
sethanguphandler((SIG_RET_TYPE) hangup); sethanguphandler((SIG_RET_TYPE) hangup);
#endif
#endif #endif
process_options(argc, argv); /* command line options */ process_options(argc, argv); /* command line options */
@@ -237,7 +239,9 @@ main(int argc, char *argv[])
*/ */
if (*gp.plname) { if (*gp.plname) {
getlock(); getlock();
#if defined(HANGUPHANDLING)
gp.program_state.preserve_locks = 0; /* after getlock() */ gp.program_state.preserve_locks = 0; /* after getlock() */
#endif
} }
if (*gp.plname && (nhfp = restore_saved_game()) != 0) { if (*gp.plname && (nhfp = restore_saved_game()) != 0) {
+2
View File
@@ -74,11 +74,13 @@ eraseoldlocks(void)
{ {
register int i; register int i;
#if defined(HANGUPHANDLING)
gp.program_state.preserve_locks = 0; /* not required but shows intent */ gp.program_state.preserve_locks = 0; /* not required but shows intent */
/* cannot use maxledgerno() here, because we need to find a lock name /* cannot use maxledgerno() here, because we need to find a lock name
* before starting everything (including the dungeon initialization * before starting everything (including the dungeon initialization
* that sets astral_level, needed for maxledgerno()) up * that sets astral_level, needed for maxledgerno()) up
*/ */
#endif
for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) { for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) {
/* try to remove all */ /* try to remove all */
set_levelfile_name(gl.lock, i); set_levelfile_name(gl.lock, i);
+8
View File
@@ -104,12 +104,14 @@ static int X11_io_error_handler(Display *);
static int (*old_error_handler)(Display *, XErrorEvent *); static int (*old_error_handler)(Display *, XErrorEvent *);
#if defined(HANGUPHANDLING)
#if !defined(NO_SIGNAL) && defined(SAFERHANGUP) #if !defined(NO_SIGNAL) && defined(SAFERHANGUP)
#if XtSpecificationRelease >= 6 #if XtSpecificationRelease >= 6
#define X11_HANGUP_SIGNAL #define X11_HANGUP_SIGNAL
static XtSignalId X11_sig_id; static XtSignalId X11_sig_id;
#endif #endif
#endif #endif
#endif
/* Interface definition, for windows.c */ /* Interface definition, for windows.c */
struct window_procs X11_procs = { struct window_procs X11_procs = {
@@ -1522,9 +1524,11 @@ static void
X11_error_handler(String str) X11_error_handler(String str)
{ {
nhUse(str); nhUse(str);
#if defined(HANGUPHANDLING)
hangup(1); hangup(1);
#ifdef SAFERHANGUP /* keeps going after hangup() for '#if SAFERHANGUP' */ #ifdef SAFERHANGUP /* keeps going after hangup() for '#if SAFERHANGUP' */
end_of_input(); end_of_input();
#endif
#endif #endif
/*NOTREACHED*/ /*NOTREACHED*/
nh_terminate(EXIT_FAILURE); nh_terminate(EXIT_FAILURE);
@@ -1534,9 +1538,11 @@ static int
X11_io_error_handler(Display *display) X11_io_error_handler(Display *display)
{ {
nhUse(display); nhUse(display);
#if defined(HANGUPHANDLING)
hangup(1); hangup(1);
#ifdef SAFERHANGUP /* keeps going after hangup() for '#if SAFERHANGUP' */ #ifdef SAFERHANGUP /* keeps going after hangup() for '#if SAFERHANGUP' */
end_of_input(); end_of_input();
#endif
#endif #endif
/*NOREACHED*/ /* but not declared NORETURN */ /*NOREACHED*/ /* but not declared NORETURN */
return 0; return 0;
@@ -1765,7 +1771,9 @@ X11_hangup(Widget w, XEvent *event, String *params, Cardinal *num_params)
nhUse(params); nhUse(params);
nhUse(num_params); nhUse(num_params);
#if defined(HANGUPHANDLING)
hangup(1); /* 1 is commonly SIGHUP, but ignored anyway */ hangup(1); /* 1 is commonly SIGHUP, but ignored anyway */
#endif
exit_x_event = TRUE; exit_x_event = TRUE;
} }
+7 -3
View File
@@ -2006,10 +2006,12 @@ x_event(int exit_condition)
inptr = (inptr + 1) % INBUF_SIZE; inptr = (inptr + 1) % INBUF_SIZE;
/* pkey(retval); */ /* pkey(retval); */
keep_going = FALSE; keep_going = FALSE;
} else if (gp.program_state.done_hup) { #if defined(HANGUPHANDLING)
} else if (gp.program_state.done_hup) {
retval = '\033'; retval = '\033';
inptr = (inptr + 1) % INBUF_SIZE; inptr = (inptr + 1) % INBUF_SIZE;
keep_going = FALSE; keep_going = FALSE;
#endif
} }
break; break;
case EXIT_ON_KEY_OR_BUTTON_PRESS: case EXIT_ON_KEY_OR_BUTTON_PRESS:
@@ -2025,11 +2027,13 @@ x_event(int exit_condition)
/* pkey(retval); */ /* pkey(retval); */
} }
keep_going = FALSE; keep_going = FALSE;
} else if (gp.program_state.done_hup) { #if defined(HANGUPHANDLING)
} else if (gp.program_state.done_hup) {
retval = '\033'; retval = '\033';
inptr = (inptr + 1) % INBUF_SIZE; inptr = (inptr + 1) % INBUF_SIZE;
keep_going = FALSE; keep_going = FALSE;
} #endif
}
break; break;
default: default:
panic("x_event: unknown exit condition %d", exit_condition); panic("x_event: unknown exit condition %d", exit_condition);
+25 -5
View File
@@ -1220,7 +1220,11 @@ X11_player_selection_dialog(void)
if (plsel_align_radios) if (plsel_align_radios)
free(plsel_align_radios); free(plsel_align_radios);
if (ps_selected == PS_QUIT || gp.program_state.done_hup) { if (ps_selected == PS_QUIT
#if defined(HANGUPHANDLING)
|| gp.program_state.done_hup
#endif
) {
clearlocks(); clearlocks();
X11_exit_nhwindows((char *) 0); X11_exit_nhwindows((char *) 0);
nh_terminate(0); nh_terminate(0);
@@ -1294,7 +1298,11 @@ X11_player_selection_prompts(void)
XtDestroyWidget(popup); XtDestroyWidget(popup);
free((genericptr_t) choices), choices = 0; free((genericptr_t) choices), choices = 0;
if (ps_selected == PS_QUIT || gp.program_state.done_hup) { if (ps_selected == PS_QUIT
#if defined(HANGUPHANDLING)
|| gp.program_state.done_hup
#endif
) {
clearlocks(); clearlocks();
X11_exit_nhwindows((char *) 0); X11_exit_nhwindows((char *) 0);
nh_terminate(0); nh_terminate(0);
@@ -1363,7 +1371,11 @@ X11_player_selection_prompts(void)
XtDestroyWidget(popup); XtDestroyWidget(popup);
free((genericptr_t) choices), choices = 0; free((genericptr_t) choices), choices = 0;
if (ps_selected == PS_QUIT || gp.program_state.done_hup) { if (ps_selected == PS_QUIT
#if defined(HANGUPHANDLING)
|| gp.program_state.done_hup
#endif
) {
clearlocks(); clearlocks();
X11_exit_nhwindows((char *) 0); X11_exit_nhwindows((char *) 0);
nh_terminate(0); nh_terminate(0);
@@ -1431,7 +1443,11 @@ X11_player_selection_prompts(void)
XtDestroyWidget(popup); XtDestroyWidget(popup);
free((genericptr_t) choices), choices = 0; free((genericptr_t) choices), choices = 0;
if (ps_selected == PS_QUIT || gp.program_state.done_hup) { if (ps_selected == PS_QUIT
#if defined(HANGUPHANDLING)
|| gp.program_state.done_hup
#endif
) {
clearlocks(); clearlocks();
X11_exit_nhwindows((char *) 0); X11_exit_nhwindows((char *) 0);
nh_terminate(0); nh_terminate(0);
@@ -1497,7 +1513,11 @@ X11_player_selection_prompts(void)
XtDestroyWidget(popup); XtDestroyWidget(popup);
free((genericptr_t) choices), choices = 0; free((genericptr_t) choices), choices = 0;
if (ps_selected == PS_QUIT || gp.program_state.done_hup) { if (ps_selected == PS_QUIT
#if defined(HANGUPHANDLING)
|| gp.program_state.done_hup
#endif
) {
clearlocks(); clearlocks();
X11_exit_nhwindows((char *) 0); X11_exit_nhwindows((char *) 0);
nh_terminate(0); nh_terminate(0);