From: Nick Mathewson Date: Tue, 22 Oct 2019 16:15:06 +0000 (-0400) Subject: Merge remote-tracking branch 'tor-github/pr/1303' into maint-0.4.1 X-Git-Tag: tor-0.4.1.7~21^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9769df89fe5bd8ccd802064273cca09efddc2b02;p=thirdparty%2Ftor.git Merge remote-tracking branch 'tor-github/pr/1303' into maint-0.4.1 --- 9769df89fe5bd8ccd802064273cca09efddc2b02 diff --cc src/lib/log/log.c index 6667c26864,4adcc5cf57..ec7c2fa24e --- a/src/lib/log/log.c +++ b/src/lib/log/log.c @@@ -806,12 -831,33 +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