Skip to content

Commit

Permalink
util/debug: exit is not thread safe
Browse files Browse the repository at this point in the history
The exit() function is not thread safe and triggers a warning from
clang tidy for all FatalError() and FatalErrorAtInit() calls.

This patch uses quick_exit instead to only flush the critical IO
and not call the static destructors (which are the non thread safe
part).
  • Loading branch information
regit committed Dec 27, 2024
1 parent e8ab4d3 commit 0132180
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@
[], [
#include <x86intrin.h>
])
AC_CHECK_DECL([quick_exit],
AC_DEFINE([HAVE_QUICK_EXIT], [1], [Use quick_exit]),
[], [
#include <stdlib.h>
])

AC_CHECK_HEADERS([malloc.h])
AC_CHECK_DECL([malloc_trim],
Expand Down
8 changes: 6 additions & 2 deletions src/util-debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,14 @@ void SCLogErr(int x, const char *file, const char *func, const int line, const c

#endif /* DEBUG */

#if !HAVE_QUICK_EXIT
#define quick_exit exit
#endif

#define FatalError(...) \
do { \
SCLogError(__VA_ARGS__); \
exit(EXIT_FAILURE); \
quick_exit(EXIT_FAILURE); \
} while (0)

/** \brief Fatal error IF we're starting up, and configured to consider
Expand All @@ -515,7 +519,7 @@ void SCLogErr(int x, const char *file, const char *func, const int line, const c
(void)ConfGetBool("engine.init-failure-fatal", &init_errors_fatal); \
if (init_errors_fatal && (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT)) { \
SCLogError(__VA_ARGS__); \
exit(EXIT_FAILURE); \
quick_exit(EXIT_FAILURE); \
} \
SCLogWarning(__VA_ARGS__); \
} while (0)
Expand Down

0 comments on commit 0132180

Please sign in to comment.