[tor-commits] [tor/master] Simplify explicit conditional checks into an inlined function.

nickm at torproject.org nickm at torproject.org
Tue Dec 12 14:25:46 UTC 2017


commit cbc465a3d1496d43c9bf28cfaf20d7409a2070b7
Author: Alexander Færøy <ahf at torproject.org>
Date:   Tue Dec 12 01:17:57 2017 +0000

    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
---
 src/common/log.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/common/log.c b/src/common/log.c
index ad3d1affd..996840a08 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -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;





More information about the tor-commits mailing list