libroot: Call abort() only if a signal handler is installed.

Preserving the assert failure message in debug reports is desirable,
so if possible we should do so, not just print it to stderr. So
now we reuse the same trick from abort() directly.

Sorry for the extra noise; I should have combined these commits.
This commit is contained in:
Augustin Cavalier 2019-01-22 22:02:59 -05:00
parent 7282d46cef
commit 2b4b201847
2 changed files with 13 additions and 5 deletions

View File

@ -18,7 +18,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
PWD_BACKEND = pwd.cpp grp.cpp shadow.cpp user_group_common.cpp ;
}
MergeObject <$(architecture)>posix_main.o :
assert.c
assert.cpp
dlfcn.c
dirent.c
errno.c

View File

@ -1,5 +1,6 @@
/*
* Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Copyright 2019, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
@ -10,6 +11,7 @@
#include <OS.h>
#include <assert.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
@ -18,11 +20,19 @@ extern char* __progname;
void
__assert_fail(const char *assertion, const char* file, unsigned int line,
__assert_fail(const char* assertion, const char* file, unsigned int line,
const char* function)
{
fprintf(stderr, "%s: %s:%d:%s: %s\n", __progname, file, line, function,
assertion);
// 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(assertion);
}
abort();
}
@ -31,7 +41,5 @@ void
__assert_perror_fail(int error, const char* file, unsigned int line,
const char* function)
{
fprintf(stderr, "%s: %s:%d:%s: %s\n", __progname, file, line, function,
strerror(error));
abort();
__assert_fail(strerror(error), file, line, function);
}