This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new a60449bd127 libs/libc/stdlib: Raise SIGABRT in abort().
a60449bd127 is described below
commit a60449bd1274529dc49713043d3c6fd7c9ef322c
Author: Marco Casaroli <[email protected]>
AuthorDate: Mon Oct 12 18:33:06 2026 +0200
libs/libc/stdlib: Raise SIGABRT in abort().
abort() called _exit() at once: a handler of SIGABRT never ran, and
the comment above the function, which describes the POSIX behavior,
was not true.
With CONFIG_ENABLE_ALL_SIGNALS, unblock and raise SIGABRT. If a
handler returns, or SIGABRT is ignored, restore the default action and
raise it again. _exit() stays as the last step.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
libs/libc/stdlib/lib_abort.c | 32 ++++++++++++++++++++++++++------
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/libs/libc/stdlib/lib_abort.c b/libs/libc/stdlib/lib_abort.c
index 4f41a2ec8ac..b74eae539fb 100644
--- a/libs/libc/stdlib/lib_abort.c
+++ b/libs/libc/stdlib/lib_abort.c
@@ -26,8 +26,11 @@
#include <nuttx/config.h>
+#include <signal.h>
#include <stdlib.h>
+#include <string.h>
#include <pthread.h>
+#include <unistd.h>
/****************************************************************************
* Public Functions
@@ -60,12 +63,29 @@
void abort(void)
{
- /* NuttX does not support standard signal functionality (like the
- * behavior of the SIGABRT signal). So no attempt is made to provide
- * a conformant version of abort() at this time. This version does not
- * signal the calling thread all.
- *
- * _exit() will close all open files and terminate the thread.
+#ifdef CONFIG_ENABLE_ALL_SIGNALS
+ struct sigaction act;
+ sigset_t set;
+
+ /* Unblock SIGABRT and raise it: a handler can catch it */
+
+ sigemptyset(&set);
+ sigaddset(&set, SIGABRT);
+ sigprocmask(SIG_UNBLOCK, &set, NULL);
+ raise(SIGABRT);
+
+ /* The handler returned, or SIGABRT is ignored: restore the default
+ * action and raise SIGABRT again.
+ */
+
+ memset(&act, 0, sizeof(act));
+ act.sa_handler = SIG_DFL;
+ sigaction(SIGABRT, &act, NULL);
+ raise(SIGABRT);
+#endif
+
+ /* SIGABRT has no default action, or signals are not enabled. _exit()
+ * closes all open files and terminates the process.
*/
_exit(EXIT_FAILURE);