diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-07-25 12:12:35 +0200 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-11-18 10:43:15 -0500 |
commit | ce8ae49c9437086a886af631d3f618ec338637d0 (patch) | |
tree | b3b41a6ac2544c83ca7a8c6d4bb040cb3c4c37f1 | |
parent | bd8ad674b913582b6f8e5b85ac722e14598d681b (diff) | |
download | tor-ce8ae49c9437086a886af631d3f618ec338637d0.tar.gz tor-ce8ae49c9437086a886af631d3f618ec338637d0.zip |
Improve new assertion message logging
Don't report that a failure happened in the assertion_failed function just
because we logged it from there.
-rw-r--r-- | src/common/log.c | 19 | ||||
-rw-r--r-- | 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 3ce4df190c..dffda45c57 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 903237940e..d210c8b249 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; |