[tor-commits] [tor/maint-0.4.1] backtrace: Disable signal handlers in remove_bt_handler()

nickm at torproject.org nickm at torproject.org
Tue Oct 22 16:14:20 UTC 2019


commit 6b97a5a843341b5ea2a9039bdd5290d524a44cd4
Author: teor <teor at torproject.org>
Date:   Wed Sep 4 14:50:09 2019 +1000

    backtrace: Disable signal handlers in remove_bt_handler()
    
    Fixes bug 31614; bugfix on 0.2.5.2-alpha.
---
 src/lib/err/backtrace.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/lib/err/backtrace.c b/src/lib/err/backtrace.c
index 1d1b3bcfa..77dc6b8cb 100644
--- a/src/lib/err/backtrace.c
+++ b/src/lib/err/backtrace.c
@@ -190,13 +190,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(const char *software)
 {
-  int trap_signals[] = { SIGSEGV, SIGILL, SIGFPE, SIGBUS, SIGSYS,
-                         SIGIO, -1 };
   int i, rv=0;
 
   strncpy(bt_version, software, sizeof(bt_version) - 1);
@@ -235,6 +237,19 @@ install_bt_handler(const char *software)
 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);
+  }
 }
 #endif /* defined(USE_BACKTRACE) */
 





More information about the tor-commits mailing list