diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-09-10 22:39:55 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-09-10 22:39:55 -0400 |
commit | de114587f047b337cf49e6a308be22f373b4bfc8 (patch) | |
tree | b4a5f3a16ee00fc9dce152435938214a8b58ff31 /src/common/log.c | |
parent | 15a318b49acfb2b7618b25cf8cddf813c745f3ab (diff) | |
download | tor-de114587f047b337cf49e6a308be22f373b4bfc8.tar.gz tor-de114587f047b337cf49e6a308be22f373b4bfc8.zip |
Turn log loop into a for loop, and "Does this lf want this" into a fn
Diffstat (limited to 'src/common/log.c')
-rw-r--r-- | src/common/log.c | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/common/log.c b/src/common/log.c index 193389c504..544aae964b 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -354,6 +354,26 @@ pending_log_message_free(pending_log_message_t *msg) tor_free(msg); } +/** Return true iff <b>lf</b> would like to receive a message with the specified + * <b>severity</b> in the specified <b>domain</b>. + */ +static INLINE int +logfile_wants_message(const logfile_t *lf, int severity, + log_domain_mask_t domain) +{ + if (! (lf->severities->masks[SEVERITY_MASK_IDX(severity)] & domain)) { + return 0; + } + if (! (lf->fd >= 0 || lf->is_syslog || lf->callback)) { + return 0; + } + if (lf->seems_dead) { + return 0; + } + + return 1; +} + /** Helper: sends a message to the appropriate logfiles, at loglevel * <b>severity</b>. If provided, <b>funcname</b> is prepended to the * message. The actual message is derived as from tor_snprintf(format,ap). @@ -379,20 +399,9 @@ logv,(int severity, log_domain_mask_t domain, const char *funcname, if ((! (domain & LD_NOCB)) && smartlist_len(pending_cb_messages)) flush_pending_log_callbacks(); - lf = logfiles; - while (lf) { - if (! (lf->severities->masks[SEVERITY_MASK_IDX(severity)] & domain)) { - lf = lf->next; - continue; - } - if (! (lf->fd >= 0 || lf->is_syslog || lf->callback)) { - lf = lf->next; - continue; - } - if (lf->seems_dead) { - lf = lf->next; + for (lf = logfiles; lf; lf = lf->next) { + if (! logfile_wants_message(lf, severity, domain)) continue; - } if (!formatted) { end_of_prefix = @@ -421,7 +430,6 @@ logv,(int severity, log_domain_mask_t domain, const char *funcname, } #endif #endif - lf = lf->next; continue; } else if (lf->callback) { if (domain & LD_NOCB) { @@ -433,7 +441,6 @@ logv,(int severity, log_domain_mask_t domain, const char *funcname, } else { lf->callback(severity, domain, end_of_prefix); } - lf = lf->next; continue; } if (write_all(lf->fd, buf, msg_len, 0) < 0) { /* error */ @@ -441,7 +448,6 @@ logv,(int severity, log_domain_mask_t domain, const char *funcname, * continue. */ lf->seems_dead = 1; } - lf = lf->next; } UNLOCK_LOGS(); } |