Skip to content

Commit

Permalink
For exits due to a signal, use non-zero exit code and indicate signal…
Browse files Browse the repository at this point in the history
… number

That is to help diagnose issues like #5952 .
  • Loading branch information
backwardsEric authored and NickMcConnell committed Apr 21, 2024
1 parent b22bdd3 commit e31f7bf
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/ui-signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,20 @@ static void handle_signal_simple(int sig)
{
/* Protect errno from library calls in signal handler */
int save_errno = errno;
/*
* Use own buffer to avoid interactions with the static variables
* used to implement vformat() (and thus quit_fmt() and format()).
*/
char msg[48];

/* Disable handler */
(void)(*signal_aux)(sig, SIG_IGN);

/* Construct the exit message in case it is needed */
(void)strnfmt(msg, sizeof(msg), "Exiting on signal %d!", sig);

/* Nothing to save, just quit */
if (!character_generated || character_saved) quit(NULL);
if (!character_generated || character_saved) quit(msg);

/* Count the signals */
signal_count++;
Expand All @@ -134,7 +142,7 @@ static void handle_signal_simple(int sig)
close_game(false);

/* Quit */
quit("interrupt");
quit(msg);
} else if (signal_count >= 5) {
#ifdef SETGID
/* Cause of "death" */
Expand All @@ -151,7 +159,7 @@ static void handle_signal_simple(int sig)
#endif

/* Quit */
quit("interrupt");
quit(msg);
} else if (signal_count >= 4) {
/*
* Remember where the cursor was so it can be restored after
Expand Down Expand Up @@ -198,11 +206,20 @@ static void handle_signal_simple(int sig)
*/
static void handle_signal_abort(int sig)
{
/*
* Use own buffer to avoid interactions with the static variables
* used to implement vformat() (and thus quit_fmt() and format()).
*/
char msg[48];

/* Disable handler */
(void)(*signal_aux)(sig, SIG_IGN);

/* Construct the exit message */
(void)strnfmt(msg, sizeof(msg), "Exiting on signal %d!", sig);

/* Nothing to save, just quit */
if (!character_generated || character_saved) quit(NULL);
if (!character_generated || character_saved) quit(msg);

/* Clear the bottom line */
Term_erase(0, 23, 255);
Expand Down Expand Up @@ -234,7 +251,7 @@ static void handle_signal_abort(int sig)
Term_fresh();

/* Quit */
quit("software bug");
quit(msg);
}


Expand Down

0 comments on commit e31f7bf

Please sign in to comment.