From: George Kadianakis Date: Mon, 30 Sep 2019 10:47:53 +0000 (+0300) Subject: Merge branch 'tor-github/pr/1302' X-Git-Tag: tor-0.4.2.2-alpha~23 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ae8d36db313a548d9828384f2131f481640c6173;p=thirdparty%2Ftor.git Merge branch 'tor-github/pr/1302' --- ae8d36db313a548d9828384f2131f481640c6173 diff --cc src/lib/err/backtrace.c index c2011285c0,2a956e6115..8bc7e6965c --- 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 4463bff618,eacd413a53..d2002f6eae --- 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 victim 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