[tor-commits] [tor/master] Improve new assertion message logging

nickm at torproject.org nickm at torproject.org
Mon Nov 18 16:04:37 UTC 2013


commit ce8ae49c9437086a886af631d3f618ec338637d0
Author: Nick Mathewson <nickm at torproject.org>
Date:   Thu Jul 25 12:12:35 2013 +0200

    Improve new assertion message logging
    
    Don't report that a failure happened in the assertion_failed function just
    because we logged it from there.
---
 src/common/log.c    |   19 +++++++++++++++----
 src/common/torlog.h |    3 +++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/common/log.c b/src/common/log.c
index 3ce4df1..dffda45 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -87,12 +87,12 @@ should_log_function_name(log_domain_mask_t domain, int severity)
     case LOG_DEBUG:
     case LOG_INFO:
       /* All debugging messages occur in interesting places. */
-      return 1;
+      return (domain & LD_NOFUNCNAME) == 0;
     case LOG_NOTICE:
     case LOG_WARN:
     case LOG_ERR:
       /* We care about places where bugs occur. */
-      return (domain == LD_BUG);
+      return (domain & (LD_BUG|LD_NOFUNCNAME)) == LD_BUG;
     default:
       /* Call assert, not tor_assert, since tor_assert calls log on failure. */
       assert(0); return 0;
@@ -525,10 +525,11 @@ void
 tor_log_update_sigsafe_err_fds(void)
 {
   const logfile_t *lf;
+  int found_real_stderr = 0;
 
   LOCK_LOGS();
-  /* Always try for stderr. This is safe because when we daemonize, we dup2
-   * /dev/null to stderr, */
+  /* Reserve the first one for stderr. This is safe because when we daemonize,
+   * we dup2 /dev/null to stderr, */
   sigsafe_log_fds[0] = STDERR_FILENO;
   n_sigsafe_log_fds = 1;
 
@@ -541,6 +542,8 @@ tor_log_update_sigsafe_err_fds(void)
       continue;
     if (lf->severities->masks[SEVERITY_MASK_IDX(LOG_ERR)] &
         (LD_BUG|LD_GENERAL)) {
+      if (lf->fd == STDERR_FILENO)
+        found_real_stderr = 1;
       /* Avoid duplicates */
       if (int_array_contains(sigsafe_log_fds, n_sigsafe_log_fds, lf->fd))
         continue;
@@ -549,6 +552,14 @@ tor_log_update_sigsafe_err_fds(void)
         break;
     }
   }
+
+  if (!found_real_stderr &&
+      int_array_contains(sigsafe_log_fds, n_sigsafe_log_fds, STDOUT_FILENO)) {
+    /* Don't use a virtual stderr when we're also logging to stdout. */
+    assert(n_sigsafe_log_fds >= 2); /* Don't use assert inside log functions*/
+    sigsafe_log_fds[0] = sigsafe_log_fds[--n_sigsafe_log_fds];
+  }
+
   UNLOCK_LOGS();
 }
 
diff --git a/src/common/torlog.h b/src/common/torlog.h
index 9032379..d210c8b 100644
--- a/src/common/torlog.h
+++ b/src/common/torlog.h
@@ -102,6 +102,9 @@
 /** This log message is not safe to send to a callback-based logger
  * immediately.  Used as a flag, not a log domain. */
 #define LD_NOCB (1u<<31)
+/** This log message should not include a function name, even if it otherwise
+ * would. Used as a flag, not a log domain. */
+#define LD_NOFUNCNAME (1u<<30)
 
 /** Mask of zero or more log domains, OR'd together. */
 typedef uint32_t log_domain_mask_t;





More information about the tor-commits mailing list