aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-12-14 12:33:53 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-12-14 13:42:48 +0000
commit2a9268f256233fc184a76083a284060391234214 (patch)
treec42c98c807b20a62ec562f9bb4e0769c270d0ece
parente415626203bec3746f7ce9d4d6681e3b938dd05d (diff)
downloadrspamd-2a9268f256233fc184a76083a284060391234214.tar.gz
rspamd-2a9268f256233fc184a76083a284060391234214.zip
[Rework] Change logger setup interface
-rw-r--r--src/libserver/task.c3
-rw-r--r--src/libutil/logger.c41
-rw-r--r--src/libutil/logger.h3
-rw-r--r--src/rspamadm/configdump.c3
-rw-r--r--src/rspamadm/configtest.c3
-rw-r--r--src/rspamadm/rspamadm.c3
-rw-r--r--src/rspamd.c15
7 files changed, 49 insertions, 22 deletions
diff --git a/src/libserver/task.c b/src/libserver/task.c
index 42f5e305e..5ef1fedb6 100644
--- a/src/libserver/task.c
+++ b/src/libserver/task.c
@@ -208,6 +208,9 @@ rspamd_task_free (struct rspamd_task *task)
if (p->raw_headers) {
g_hash_table_unref (p->raw_headers);
}
+ if (p->children) {
+ g_ptr_array_free (p->children, TRUE);
+ }
}
for (i = 0; i < task->text_parts->len; i ++) {
diff --git a/src/libutil/logger.c b/src/libutil/logger.c
index 082c12d14..8707acb39 100644
--- a/src/libutil/logger.c
+++ b/src/libutil/logger.c
@@ -130,7 +130,12 @@ direct_write_log_line (rspamd_logger_t *rspamd_log,
if (rspamd_log->enabled) {
if (!rspamd_log->no_lock) {
#ifndef DISABLE_PTHREAD_MUTEX
- rspamd_mempool_lock_mutex (rspamd_log->mtx);
+ if (rspamd_log->mtx) {
+ rspamd_mempool_lock_mutex (rspamd_log->mtx);
+ }
+ else {
+ rspamd_file_lock (rspamd_log->fd, FALSE);
+ }
#else
rspamd_file_lock (rspamd_log->fd, FALSE);
#endif
@@ -147,7 +152,12 @@ direct_write_log_line (rspamd_logger_t *rspamd_log,
if (!rspamd_log->no_lock) {
#ifndef DISABLE_PTHREAD_MUTEX
- rspamd_mempool_unlock_mutex (rspamd_log->mtx);
+ if (rspamd_log->mtx) {
+ rspamd_mempool_unlock_mutex (rspamd_log->mtx);
+ }
+ else {
+ rspamd_file_unlock (rspamd_log->fd, FALSE);
+ }
#else
rspamd_file_unlock (rspamd_log->fd, FALSE);
#endif
@@ -342,28 +352,35 @@ rspamd_log_reopen (rspamd_logger_t *logger)
void
rspamd_set_logger (struct rspamd_config *cfg,
GQuark ptype,
- struct rspamd_main *rspamd)
+ rspamd_logger_t **plogger,
+ rspamd_mempool_t *pool)
{
rspamd_logger_t *logger;
- if (rspamd->logger == NULL) {
- rspamd->logger = g_slice_alloc0 (sizeof (rspamd_logger_t));
- logger = rspamd->logger;
+ if (plogger == NULL || *plogger == NULL) {
+ logger = g_slice_alloc0 (sizeof (rspamd_logger_t));
- if (cfg->log_error_elts > 0) {
- logger->errlog = rspamd_mempool_alloc0_shared (rspamd->server_pool,
+ if (cfg->log_error_elts > 0 && pool) {
+ logger->errlog = rspamd_mempool_alloc0_shared (pool,
sizeof (*logger->errlog));
- logger->errlog->pool = rspamd->server_pool;
+ logger->errlog->pool = pool;
logger->errlog->max_elts = cfg->log_error_elts;
logger->errlog->elt_len = cfg->log_error_elt_maxlen;
- logger->errlog->elts = rspamd_mempool_alloc0_shared (rspamd->server_pool,
+ logger->errlog->elts = rspamd_mempool_alloc0_shared (pool,
sizeof (struct rspamd_logger_error_elt) * cfg->log_error_elts +
cfg->log_error_elt_maxlen * cfg->log_error_elts);
- logger->mtx = rspamd_mempool_get_mutex (rspamd->server_pool);
+ }
+
+ if (pool) {
+ logger->mtx = rspamd_mempool_get_mutex (pool);
+ }
+
+ if (plogger) {
+ *plogger = logger;
}
}
else {
- logger = rspamd->logger;
+ logger = *plogger;
}
logger->type = cfg->log_type;
diff --git a/src/libutil/logger.h b/src/libutil/logger.h
index 4aeda1dc4..57ef74d09 100644
--- a/src/libutil/logger.h
+++ b/src/libutil/logger.h
@@ -29,7 +29,8 @@ typedef struct rspamd_logger_s rspamd_logger_t;
*/
void rspamd_set_logger (struct rspamd_config *cfg,
GQuark ptype,
- struct rspamd_main *main);
+ rspamd_logger_t **plogger,
+ rspamd_mempool_t *pool);
/**
* Open log file or initialize other structures
diff --git a/src/rspamadm/configdump.c b/src/rspamadm/configdump.c
index 199a22693..355437b9c 100644
--- a/src/rspamadm/configdump.c
+++ b/src/rspamadm/configdump.c
@@ -86,7 +86,8 @@ config_logger (rspamd_mempool_t *pool, gpointer ud)
rm->cfg->log_type = RSPAMD_LOG_CONSOLE;
rm->cfg->log_level = G_LOG_LEVEL_CRITICAL;
- rspamd_set_logger (rm->cfg, g_quark_try_string ("main"), rm);
+ rspamd_set_logger (rm->cfg, g_quark_try_string ("main"), &rm->logger,
+ rm->server_pool);
if (rspamd_log_open_priv (rm->logger, rm->workers_uid, rm->workers_gid) ==
-1) {
fprintf (stderr, "Fatal error, cannot open logfile, exiting\n");
diff --git a/src/rspamadm/configtest.c b/src/rspamadm/configtest.c
index 967bca2ba..59f466de2 100644
--- a/src/rspamadm/configtest.c
+++ b/src/rspamadm/configtest.c
@@ -83,7 +83,8 @@ config_logger (rspamd_mempool_t *pool, gpointer ud)
rm->cfg->log_level = G_LOG_LEVEL_WARNING;
}
- rspamd_set_logger (rm->cfg, configtest_quark, rm);
+ rspamd_set_logger (rm->cfg, configtest_quark, &rm->logger,
+ rm->server_pool);
if (rspamd_log_open_priv (rm->logger, rm->workers_uid, rm->workers_gid) ==
-1) {
fprintf (stderr, "Fatal error, cannot open logfile, exiting\n");
diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c
index de1e53143..e242ab925 100644
--- a/src/rspamadm/rspamadm.c
+++ b/src/rspamadm/rspamadm.c
@@ -281,7 +281,8 @@ main (gint argc, gchar **argv, gchar **env)
cfg->log_level = G_LOG_LEVEL_WARNING;
cfg->log_type = RSPAMD_LOG_CONSOLE;
- rspamd_set_logger (cfg, process_quark, rspamd_main);
+ rspamd_set_logger (cfg, process_quark, &rspamd_main->logger,
+ rspamd_main->server_pool);
(void) rspamd_log_open (rspamd_main->logger);
g_log_set_default_handler (rspamd_glib_log_function, rspamd_main->logger);
g_set_printerr_handler (rspamd_glib_printerr_function);
diff --git a/src/rspamd.c b/src/rspamd.c
index 60fa243f8..9dd269045 100644
--- a/src/rspamd.c
+++ b/src/rspamd.c
@@ -255,7 +255,7 @@ config_logger (rspamd_mempool_t *pool, gpointer ud)
}
rspamd_set_logger (rspamd_main->cfg, g_quark_try_string ("main"),
- rspamd_main);
+ &rspamd_main->logger, rspamd_main->server_pool);
if (rspamd_log_open_priv (rspamd_main->logger,
rspamd_main->workers_uid, rspamd_main->workers_gid) == -1) {
fprintf (stderr, "Fatal error, cannot open logfile, exiting\n");
@@ -273,7 +273,8 @@ reread_config (struct rspamd_main *rspamd_main)
tmp_cfg->c_modules = g_hash_table_ref (rspamd_main->cfg->c_modules);
tmp_cfg->libs_ctx = rspamd_main->cfg->libs_ctx;
REF_RETAIN (tmp_cfg->libs_ctx);
- rspamd_set_logger (tmp_cfg, g_quark_try_string ("main"), rspamd_main);
+ rspamd_set_logger (tmp_cfg, g_quark_try_string ("main"),
+ &rspamd_main->logger, rspamd_main->server_pool);
cfg_file = rspamd_mempool_strdup (tmp_cfg->cfg_pool,
rspamd_main->cfg->cfg_name);
/* Save some variables */
@@ -281,8 +282,8 @@ reread_config (struct rspamd_main *rspamd_main)
if (!load_rspamd_config (rspamd_main, tmp_cfg, TRUE,
RSPAMD_CONFIG_INIT_VALIDATE|RSPAMD_CONFIG_INIT_SYMCACHE)) {
- rspamd_set_logger (rspamd_main->cfg, g_quark_try_string (
- "main"), rspamd_main);
+ rspamd_set_logger (rspamd_main->cfg, g_quark_try_string ("main"),
+ &rspamd_main->logger, rspamd_main->server_pool);
msg_err_main ("cannot parse new config file, revert to old one");
REF_RELEASE (tmp_cfg);
}
@@ -291,7 +292,8 @@ reread_config (struct rspamd_main *rspamd_main)
REF_RELEASE (rspamd_main->cfg);
rspamd_main->cfg = tmp_cfg;
- rspamd_set_logger (tmp_cfg, g_quark_try_string ("main"), rspamd_main);
+ rspamd_set_logger (tmp_cfg, g_quark_try_string ("main"),
+ &rspamd_main->logger, rspamd_main->server_pool);
/* Force debug log */
if (is_debug) {
rspamd_main->cfg->log_level = G_LOG_LEVEL_DEBUG;
@@ -1137,7 +1139,8 @@ main (gint argc, gchar **argv, gchar **env)
/* First set logger to console logger */
rspamd_main->cfg->log_type = RSPAMD_LOG_CONSOLE;
- rspamd_set_logger (rspamd_main->cfg, type, rspamd_main);
+ rspamd_set_logger (rspamd_main->cfg, type,
+ &rspamd_main->logger, rspamd_main->server_pool);
(void) rspamd_log_open (rspamd_main->logger);
g_log_set_default_handler (rspamd_glib_log_function, rspamd_main->logger);
g_set_printerr_handler (rspamd_glib_printerr_function);