1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00

The SIGABRT handler can no longer invoke abort() recursively.

This commit is contained in:
obarthel
2023-09-10 11:45:38 +02:00
parent 64ab8643b5
commit 9a9ae7d6fd
2 changed files with 33 additions and 25 deletions

View File

@@ -88,14 +88,15 @@ raise(int sig)
/* Which handler is installed for this signal? */ /* Which handler is installed for this signal? */
handler = __signal_handler_table[sig - SIGABRT]; handler = __signal_handler_table[sig - SIGABRT];
/* Should we ignore this signal? */ /* Should we handle this signal rather than ignoring it? */
if (handler != SIG_IGN) if (handler != SIG_IGN)
{ {
/* Block delivery of this signal to prevent recursion. */ /* Block delivery of this signal to prevent recursion. */
SET_FLAG(local_signals_blocked, (1 << sig)); SET_FLAG(local_signals_blocked, (1 << sig));
/* The default behaviour is to drop into abort(), or do /* The default behaviour is to drop into abort(), or do
something very much like it. */ * something very much like it.
*/
if (handler == SIG_DFL) if (handler == SIG_DFL)
{ {
SHOWMSG("this is the default handler"); SHOWMSG("this is the default handler");
@@ -114,14 +115,14 @@ raise(int sig)
SHOWMSG("bye, bye..."); SHOWMSG("bye, bye...");
} }
/* Drop straight into abort(), which might call signal() /* Drop straight into __abort(), which will
again but is otherwise guaranteed to eventually eventually land us in _exit(). Note that
land us in _exit(). */ abort() calls raise(SIGABRT). */
abort(); __abort();
} }
else else
{ {
SHOWMSG("calling the handler"); SHOWMSG("calling the signal handler");
(*handler)(sig); (*handler)(sig);

View File

@@ -46,15 +46,8 @@
/****************************************************************************/ /****************************************************************************/
void void
abort(void) __abort(void)
{ {
/* Try to call the signal handler that might be in charge of
handling cleanup operations, etc. */
raise(SIGABRT);
/* If the signal handler returns it means that we still have
to terminate the program. */
__check_abort_enabled = FALSE; __check_abort_enabled = FALSE;
__print_termination_message(NULL); __print_termination_message(NULL);
@@ -63,3 +56,17 @@ abort(void)
does not trigger the exit trap. */ does not trigger the exit trap. */
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
/****************************************************************************/
void
abort(void)
{
/* Try to call the signal handler that might be in charge of
handling cleanup operations, etc. */
raise(SIGABRT);
/* If the signal handler returns it means that we still have
to terminate the program. */
__abort();
}