Simplify explicit conditional checks into an inlined function.

This patch lifts the check for whether a given log file (`logfile_t`) is
an "external logfile" (handled by an external logging system such as
syslog, android's logging subsystem, or as an external C callback
function) into a function on its own.

See: https://bugs.torproject.org/24362
This commit is contained in:
Alexander Færøy 2017-12-12 01:17:57 +00:00
parent b0b8f7c30c
commit cbc465a3d1
1 changed files with 14 additions and 4 deletions

View File

@ -433,6 +433,16 @@ pending_log_message_free_(pending_log_message_t *msg)
tor_free(msg);
}
/** Helper function: returns true iff the log file, given in <b>lf</b>, is
* handled externally via the system log API, the Android logging API, or is an
* external callback function. */
static inline int
logfile_is_external(logfile_t *lf)
{
raw_assert(lf);
return lf->is_syslog || lf->is_android || lf->callback;
}
/** Return true iff <b>lf</b> would like to receive a message with the
* specified <b>severity</b> in the specified <b>domain</b>.
*/
@ -443,7 +453,7 @@ logfile_wants_message(const logfile_t *lf, int severity,
if (! (lf->severities->masks[SEVERITY_MASK_IDX(severity)] & domain)) {
return 0;
}
if (! (lf->fd >= 0 || lf->is_syslog || lf->is_android || lf->callback)) {
if (! (lf->fd >= 0 || logfile_is_external(lf))) {
return 0;
}
if (lf->seems_dead) {
@ -683,8 +693,8 @@ tor_log_update_sigsafe_err_fds(void)
/* Don't try callback to the control port, or syslogs: We can't
* do them from a signal handler. Don't try stdout: we always do stderr.
*/
if (lf->is_temporary || lf->is_syslog || lf->is_android ||
lf->callback || lf->seems_dead || lf->fd < 0)
if (lf->is_temporary || logfile_is_external(lf)
|| lf->seems_dead || lf->fd < 0)
continue;
if (lf->severities->masks[SEVERITY_MASK_IDX(LOG_ERR)] &
(LD_BUG|LD_GENERAL)) {
@ -720,7 +730,7 @@ tor_log_get_logfile_names(smartlist_t *out)
LOCK_LOGS();
for (lf = logfiles; lf; lf = lf->next) {
if (lf->is_temporary || lf->is_syslog || lf->is_android || lf->callback)
if (lf->is_temporary || logfile_is_external(lf))
continue;
if (lf->filename == NULL)
continue;