diff --git a/src/system/libroot/posix/Jamfile b/src/system/libroot/posix/Jamfile index 2079067016..6aa077ab8a 100644 --- a/src/system/libroot/posix/Jamfile +++ b/src/system/libroot/posix/Jamfile @@ -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 diff --git a/src/system/libroot/posix/assert.c b/src/system/libroot/posix/assert.cpp similarity index 55% rename from src/system/libroot/posix/assert.c rename to src/system/libroot/posix/assert.cpp index c840b54bdd..851ca17bf7 100644 --- a/src/system/libroot/posix/assert.c +++ b/src/system/libroot/posix/assert.cpp @@ -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 #include +#include #include #include @@ -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); }