diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-02-10 20:53:22 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-02-10 21:12:13 +0000 |
commit | 3424122c9d082d53e8c437066d34cf602380a69c (patch) | |
tree | 85bd4b9503d3a903a55996c3c646f0c4c28195f8 /src/libutil | |
parent | 7630467d757c27fab944cda366e78ac82d45ff55 (diff) | |
download | rspamd-3424122c9d082d53e8c437066d34cf602380a69c.tar.gz rspamd-3424122c9d082d53e8c437066d34cf602380a69c.zip |
[Rework] Logger: Fix issues found so far
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/logger.c | 38 | ||||
-rw-r--r-- | src/libutil/logger_console.c | 6 | ||||
-rw-r--r-- | src/libutil/logger_private.h | 1 |
3 files changed, 40 insertions, 5 deletions
diff --git a/src/libutil/logger.c b/src/libutil/logger.c index af71665fd..4fed80d3e 100644 --- a/src/libutil/logger.c +++ b/src/libutil/logger.c @@ -66,6 +66,12 @@ rspamd_log_close (rspamd_logger_t *logger) { g_assert (logger != NULL); + if (logger->closed) { + return; + } + + logger->closed = TRUE; + if (logger->debug_ip) { rspamd_map_helper_destroy_radix (logger->debug_ip); } @@ -105,6 +111,15 @@ rspamd_log_reopen (rspamd_logger_t *rspamd_log, struct rspamd_config *cfg, nspec = rspamd_log->ops.reload (rspamd_log, cfg, rspamd_log->ops.specific, uid, gid, &err); + + if (nspec != NULL) { + rspamd_log->ops.specific = nspec; + } + else { + + } + + return nspec != NULL; } static void @@ -116,7 +131,7 @@ rspamd_emergency_logger_dtor (gpointer d) } rspamd_logger_t * -rspamd_log_init (rspamd_mempool_t *pool) +rspamd_log_open_emergency (rspamd_mempool_t *pool) { rspamd_logger_t *logger; GError *err = NULL; @@ -167,8 +182,7 @@ rspamd_log_open_specific (rspamd_mempool_t *pool, rspamd_logger_t *logger; GError *err = NULL; - g_assert (default_logger == NULL); - g_assert (emergency_logger == NULL); + g_assert (emergency_logger != NULL); if (pool) { logger = rspamd_mempool_alloc0 (pool, sizeof (rspamd_logger_t)); @@ -208,6 +222,17 @@ rspamd_log_open_specific (rspamd_mempool_t *pool, g_assert (funcs != NULL); memcpy (&logger->ops, funcs, sizeof (*funcs)); + logger->ops.specific = logger->ops.init (logger, cfg, uid, gid, &err); + + if (logger->ops.specific == NULL) { + rspamd_common_log_function (emergency_logger, G_LOG_LEVEL_CRITICAL, + "logger", NULL, G_STRFUNC, + "cannot open specific logger: %e", err); + g_error_free (err); + + return NULL; + } + logger->pid = getpid (); logger->process_type = ptype; @@ -241,6 +266,8 @@ rspamd_log_open_specific (rspamd_mempool_t *pool, } default_logger = logger; + + return logger; } @@ -358,7 +385,7 @@ rspamd_log_write_ringbuffer (rspamd_logger_t *rspamd_log, } elt->pid = rspamd_log->pid; - elt->ptype = rspamd_log->process_type; + elt->ptype = g_quark_from_string (rspamd_log->process_type); elt->ts = rspamd_get_calendar_ticks (); if (id) { @@ -846,4 +873,7 @@ struct rspamd_logger_funcs* rspamd_logger_set_log_function (rspamd_logger_t *logger, struct rspamd_logger_funcs *nfuncs) { + /* TODO: write this */ + + return NULL; }
\ No newline at end of file diff --git a/src/libutil/logger_console.c b/src/libutil/logger_console.c index fae12ea11..05bb67f21 100644 --- a/src/libutil/logger_console.c +++ b/src/libutil/logger_console.c @@ -76,7 +76,7 @@ rspamd_log_console_init (rspamd_logger_t *logger, struct rspamd_config *cfg, if (priv->fd == -1) { g_set_error (err, CONSOLE_LOG_QUARK, errno, - "open_log: cannot dup console fd: %s, %s\n", + "open_log: cannot dup console fd: %s\n", strerror (errno)); rspamd_log_console_dtor (logger, priv); @@ -85,6 +85,10 @@ rspamd_log_console_init (rspamd_logger_t *logger, struct rspamd_config *cfg, if (isatty (priv->fd)) { priv->log_tty = true; + + if (priv->log_color) { + priv->log_color = false; + } } return priv; diff --git a/src/libutil/logger_private.h b/src/libutil/logger_private.h index f4b6fe8d6..23361e38d 100644 --- a/src/libutil/logger_private.h +++ b/src/libutil/logger_private.h @@ -67,6 +67,7 @@ struct rspamd_logger_s { struct rspamd_cryptobox_keypair *keypair; guint flags; + gboolean closed; gboolean enabled; gboolean is_debug; gboolean no_lock; |