diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-11-01 17:52:15 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-11-01 17:52:15 +0000 |
commit | 75ef01b07b276ead8199f85a8942735f5b762028 (patch) | |
tree | 784d00c63e5c9f1b33de8986dbdc5ec48c4203e5 | |
parent | 57708d0d30318b096479d0c8c6d90c7ed7b6f960 (diff) | |
download | rspamd-75ef01b07b276ead8199f85a8942735f5b762028.tar.gz rspamd-75ef01b07b276ead8199f85a8942735f5b762028.zip |
Use process-level mutex to avoid log races.
-rw-r--r-- | src/libutil/logger.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/libutil/logger.c b/src/libutil/logger.c index f25c1fe75..c4c36b4f8 100644 --- a/src/libutil/logger.c +++ b/src/libutil/logger.c @@ -61,7 +61,8 @@ struct rspamd_logger_s { guint32 repeats; gchar *saved_message; gchar *saved_function; - GMutex *mtx; + rspamd_mempool_t *pool; + rspamd_mempool_mutex_t *mtx; }; static const gchar lf_chr = '\n'; @@ -299,12 +300,9 @@ rspamd_set_logger (struct rspamd_config *cfg, rspamd->logger->pid = getpid (); rspamd->logger->process_type = ptype; -#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION <= 30)) - rspamd->logger->mtx = g_mutex_new (); -#else - rspamd->logger->mtx = g_malloc (sizeof (GMutex)); - g_mutex_init (rspamd->logger->mtx); -#endif + /* Small pool for interlocking */ + rspamd->logger->pool = rspamd_mempool_new (512); + rspamd->logger->mtx = rspamd_mempool_get_mutex (rspamd->logger->pool); switch (cfg->log_type) { case RSPAMD_LOG_CONSOLE: @@ -406,7 +404,7 @@ rspamd_common_logv (rspamd_logger_t *rspamd_log, } } else if (log_level <= rspamd_log->cfg->log_level) { - g_mutex_lock (rspamd_log->mtx); + rspamd_mempool_lock_mutex (rspamd_log->mtx); end = rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, args); *end = '\0'; rspamd_escape_log_string (logbuf); @@ -416,7 +414,7 @@ rspamd_common_logv (rspamd_logger_t *rspamd_log, logbuf, FALSE, rspamd_log); - g_mutex_unlock (rspamd_log->mtx); + rspamd_mempool_unlock_mutex (rspamd_log->mtx); } } @@ -789,7 +787,7 @@ rspamd_conditional_debug (rspamd_logger_t *rspamd_log, return; } } - g_mutex_lock (rspamd_log->mtx); + rspamd_mempool_lock_mutex (rspamd_log->mtx); va_start (vp, fmt); end = rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, vp); *end = '\0'; @@ -801,7 +799,7 @@ rspamd_conditional_debug (rspamd_logger_t *rspamd_log, logbuf, TRUE, rspamd_log); - g_mutex_unlock (rspamd_log->mtx); + rspamd_mempool_unlock_mutex (rspamd_log->mtx); } } /** @@ -816,14 +814,14 @@ rspamd_glib_log_function (const gchar *log_domain, rspamd_logger_t *rspamd_log = arg; if (rspamd_log->enabled) { - g_mutex_lock (rspamd_log->mtx); + rspamd_mempool_lock_mutex (rspamd_log->mtx); rspamd_log->log_func (log_domain, NULL, log_level, message, FALSE, rspamd_log); - g_mutex_unlock (rspamd_log->mtx); + rspamd_mempool_unlock_mutex (rspamd_log->mtx); } } |