libroot: Fix handling of debugger() call in abort().

The kernel's handling of SIGABRT is just to terminate the application
immediately without doing anything else (it only notifies the debugger if
there's one installed for this application already.) More serious faults
(e.g. SIGSEGV) originate in the kernel and handle this logic before they
even invoke the signal handler.

So the correct solution is to do the same here in libroot. This incurs
a very, very slight performance penalty of the syscall time for sigaction(),
though I expect whatever applications are causing SIGABRT to be invoked more
than once a second will call raise() directly instead of abort()...
This commit is contained in:
Augustin Cavalier 2018-09-02 00:13:40 -04:00
parent e54f86aa6a
commit 0df493a13a

View File

@ -288,8 +288,14 @@ abort()
{
fprintf(stderr, "Abort\n");
raise(SIGABRT);
// If there's no handler installed for SIGABRT, call debugger().
struct sigaction signalAction;
if (sigaction(SIGABRT, NULL, &signalAction) == 0
&& signalAction.sa_handler == SIG_DFL) {
debugger("abort() called");
}
raise(SIGABRT);
exit(EXIT_FAILURE);
}