[tor-commits] [tor/master] Merge branch 'tor-github/pr/1302'
asn at torproject.org
asn at torproject.org
Mon Sep 30 10:53:19 UTC 2019
commit ae8d36db313a548d9828384f2131f481640c6173
Merge: fc760c508 749c2e176
Author: George Kadianakis <desnacked at riseup.net>
Date: Mon Sep 30 13:47:53 2019 +0300
Merge branch 'tor-github/pr/1302'
changes/bug31614 | 9 +++++++++
src/lib/err/backtrace.c | 26 +++++++++++++++++++++++---
src/lib/log/log.c | 5 ++++-
src/lib/sandbox/sandbox.c | 1 +
4 files changed, 37 insertions(+), 4 deletions(-)
diff --cc src/lib/err/backtrace.c
index c2011285c,2a956e611..8bc7e6965
--- a/src/lib/err/backtrace.c
+++ b/src/lib/err/backtrace.c
@@@ -193,12 -198,13 +198,10 @@@ static int trap_signals[] = { SIGSEGV,
/** 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)
+install_bt_handler(void)
{
- int trap_signals[] = { SIGSEGV, SIGILL, SIGFPE, SIGBUS, SIGSYS,
- SIGIO, -1 };
int i, rv=0;
- strncpy(bt_version, software, sizeof(bt_version) - 1);
- bt_version[sizeof(bt_version) - 1] = 0;
-
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
diff --cc src/lib/log/log.c
index 4463bff61,eacd413a5..d2002f6ea
--- a/src/lib/log/log.c
+++ b/src/lib/log/log.c
@@@ -832,33 -804,12 +832,36 @@@ logs_free_all(void
}
/* We _could_ destroy the log mutex here, but that would screw up any logs
- * that happened between here and the end of execution. */
+ * that happened between here and the end of execution.
+ * If tor is re-initialized, log_mutex_initialized will still be 1. So we
+ * won't trigger any undefined behaviour by trying to re-initialize the
+ * log mutex. */
}
+/** Close signal-safe log files.
+ * Closing the log files makes the process and OS flush log buffers.
+ *
+ * This function is safe to call from a signal handler. It should only be
+ * called when shutting down the log or err modules. It is currenly called
+ * by the err module, when terminating the process on an abnormal condition.
+ */
+void
+logs_close_sigsafe(void)
+{
+ logfile_t *victim, *next;
+ /* We can't LOCK_LOGS() in a signal handler, because it may call
+ * signal-unsafe functions. And we can't deallocate memory, either. */
+ next = logfiles;
+ logfiles = NULL;
+ while (next) {
+ victim = next;
+ next = next->next;
+ if (victim->needs_close) {
+ close_log_sigsafe(victim);
+ }
+ }
+}
+
/** Remove and free the log entry <b>victim</b> from the linked-list
* logfiles (it is probably present, but it might not be due to thread
* racing issues). After this function is called, the caller shouldn't
More information about the tor-commits
mailing list