aboutsummaryrefslogtreecommitdiff
path: root/src/lib/err
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2019-09-30 13:47:53 +0300
committerGeorge Kadianakis <desnacked@riseup.net>2019-09-30 13:47:53 +0300
commitae8d36db313a548d9828384f2131f481640c6173 (patch)
tree424a7c540b55a4f3c2e8258f548a04c6d0797651 /src/lib/err
parentfc760c5088394741ac8c83706be6b737aef79beb (diff)
parent749c2e1761c753992fb2549e7ee912e568f563d6 (diff)
downloadtor-ae8d36db313a548d9828384f2131f481640c6173.tar.gz
tor-ae8d36db313a548d9828384f2131f481640c6173.zip
Merge branch 'tor-github/pr/1302'
Diffstat (limited to 'src/lib/err')
-rw-r--r--src/lib/err/backtrace.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/lib/err/backtrace.c b/src/lib/err/backtrace.c
index c2011285c0..8bc7e6965c 100644
--- a/src/lib/err/backtrace.c
+++ b/src/lib/err/backtrace.c
@@ -57,7 +57,8 @@
#include "lib/err/torerr.h"
#if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && \
- defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_SIGACTION)
+ defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_SIGACTION) && \
+ defined(HAVE_PTHREAD_H)
#define USE_BACKTRACE
#endif
@@ -190,13 +191,15 @@ dump_stack_symbols_to_error_fds(void)
backtrace_symbols_fd(cb_buf, (int)depth, fds[i]);
}
+/* The signals that we want our backtrace handler to trap */
+static int trap_signals[] = { SIGSEGV, SIGILL, SIGFPE, SIGBUS, SIGSYS,
+ SIGIO, -1 };
+
/** Install signal handlers as needed so that when we crash, we produce a
* useful stack trace. Return 0 on success, -errno on failure. */
static int
install_bt_handler(void)
{
- int trap_signals[] = { SIGSEGV, SIGILL, SIGFPE, SIGBUS, SIGSYS,
- SIGIO, -1 };
int i, rv=0;
struct sigaction sa;
@@ -232,6 +235,23 @@ install_bt_handler(void)
static void
remove_bt_handler(void)
{
+ int i;
+
+ struct sigaction sa;
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = SIG_DFL;
+ sigfillset(&sa.sa_mask);
+
+ for (i = 0; trap_signals[i] >= 0; ++i) {
+ /* remove_bt_handler() is called on shutdown, from low-level code.
+ * It's not a fatal error, so we just ignore it. */
+ (void)sigaction(trap_signals[i], &sa, NULL);
+ }
+
+ /* cb_buf_mutex is statically initialised, so we can not destroy it.
+ * If we destroy it, and then re-initialise tor, all our backtraces will
+ * fail. */
}
#endif /* defined(USE_BACKTRACE) */