aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-03-04 13:07:07 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-03-04 13:07:33 +0000
commitb80ddf78c8508210aa1f00dc1654593a2f810c24 (patch)
treebb879a6b2de7d8538fbfd96a4354992b027a85cd /src
parentfadd570a71a8b86e8d9be5ff9dbe53f2ead4ac9f (diff)
downloadrspamd-b80ddf78c8508210aa1f00dc1654593a2f810c24.tar.gz
rspamd-b80ddf78c8508210aa1f00dc1654593a2f810c24.zip
[Minor] Respect forced flag when logging is disabled
Diffstat (limited to 'src')
-rw-r--r--src/libserver/cfg_file.h4
-rw-r--r--src/libserver/cfg_rcl.c8
-rw-r--r--src/libutil/logger.c100
3 files changed, 57 insertions, 55 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index 5b0b87f8b..f6798c9e3 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -658,6 +658,10 @@ gboolean rspamd_config_radix_from_ucl (struct rspamd_config *cfg,
cfg->cfg_pool->tag.tagname, cfg->checksum, \
G_STRFUNC, \
__VA_ARGS__)
+#define msg_err_config_forced(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL|RSPAMD_LOG_FORCED, \
+ cfg->cfg_pool->tag.tagname, cfg->checksum, \
+ G_STRFUNC, \
+ __VA_ARGS__)
#define msg_warn_config(...) rspamd_default_log_function (G_LOG_LEVEL_WARNING, \
cfg->cfg_pool->tag.tagname, cfg->checksum, \
G_STRFUNC, \
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index 8b4fa0120..f002587fa 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -3521,18 +3521,18 @@ rspamd_config_read (struct rspamd_config *cfg, const gchar *filename,
struct ucl_emitter_functions f;
if (stat (filename, &st) == -1) {
- msg_err_config ("cannot stat %s: %s", filename, strerror (errno));
+ msg_err_config_forced ("cannot stat %s: %s", filename, strerror (errno));
return FALSE;
}
if ((fd = open (filename, O_RDONLY)) == -1) {
- msg_err_config ("cannot open %s: %s", filename, strerror (errno));
+ msg_err_config_forced ("cannot open %s: %s", filename, strerror (errno));
return FALSE;
}
/* Now mmap this file to simplify reading process */
if ((data =
mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
- msg_err_config ("cannot mmap %s: %s", filename, strerror (errno));
+ msg_err_config_forced ("cannot mmap %s: %s", filename, strerror (errno));
close (fd);
return FALSE;
}
@@ -3545,7 +3545,7 @@ rspamd_config_read (struct rspamd_config *cfg, const gchar *filename,
rspamd_ucl_add_conf_macros (parser, cfg);
if (!ucl_parser_add_chunk (parser, data, st.st_size)) {
- msg_err_config ("ucl parser error: %s", ucl_parser_get_error (parser));
+ msg_err_config_forced ("ucl parser error: %s", ucl_parser_get_error (parser));
ucl_parser_free (parser);
munmap (data, st.st_size);
return FALSE;
diff --git a/src/libutil/logger.c b/src/libutil/logger.c
index 04291d8e9..920c5231b 100644
--- a/src/libutil/logger.c
+++ b/src/libutil/logger.c
@@ -136,69 +136,67 @@ direct_write_log_line (rspamd_logger_t *rspamd_log,
fd = rspamd_log->fd;
}
- if (rspamd_log->enabled) {
- if (!rspamd_log->no_lock) {
+ if (!rspamd_log->no_lock) {
#ifndef DISABLE_PTHREAD_MUTEX
- if (rspamd_log->mtx) {
- rspamd_mempool_lock_mutex (rspamd_log->mtx);
- }
- else {
- rspamd_file_lock (fd, FALSE);
- }
-#else
+ if (rspamd_log->mtx) {
+ rspamd_mempool_lock_mutex (rspamd_log->mtx);
+ }
+ else {
rspamd_file_lock (fd, FALSE);
-#endif
}
+#else
+ rspamd_file_lock (fd, FALSE);
+#endif
+ }
+
+ if (is_iov) {
+ iov = (struct iovec *) data;
+ r = writev (fd, iov, count);
+ }
+ else {
+ line = (const gchar *) data;
+ r = write (fd, line, count);
+ }
- if (is_iov) {
- iov = (struct iovec *) data;
- r = writev (fd, iov, count);
+ if (!rspamd_log->no_lock) {
+#ifndef DISABLE_PTHREAD_MUTEX
+ if (rspamd_log->mtx) {
+ rspamd_mempool_unlock_mutex (rspamd_log->mtx);
}
else {
- line = (const gchar *) data;
- r = write (fd, line, count);
+ rspamd_file_unlock (fd, FALSE);
}
-
- if (!rspamd_log->no_lock) {
-#ifndef DISABLE_PTHREAD_MUTEX
- if (rspamd_log->mtx) {
- rspamd_mempool_unlock_mutex (rspamd_log->mtx);
- }
- else {
- rspamd_file_unlock (fd, FALSE);
- }
#else
- rspamd_file_unlock (fd, FALSE);
+ rspamd_file_unlock (fd, FALSE);
#endif
- }
+ }
- if (r == -1) {
- /* We cannot write message to file, so we need to detect error and make decision */
- if (errno == EINTR) {
- /* Try again */
- direct_write_log_line (rspamd_log, data, count, is_iov);
- return;
- }
+ if (r == -1) {
+ /* We cannot write message to file, so we need to detect error and make decision */
+ if (errno == EINTR) {
+ /* Try again */
+ direct_write_log_line (rspamd_log, data, count, is_iov);
+ return;
+ }
- r = rspamd_snprintf (errmsg,
- sizeof (errmsg),
- "direct_write_log_line: cannot write log line: %s",
- strerror (errno));
- if (errno == EFAULT || errno == EINVAL || errno == EFBIG ||
+ r = rspamd_snprintf (errmsg,
+ sizeof (errmsg),
+ "direct_write_log_line: cannot write log line: %s",
+ strerror (errno));
+ if (errno == EFAULT || errno == EINVAL || errno == EFBIG ||
errno == ENOSPC) {
- /* Rare case */
- rspamd_log->throttling = TRUE;
- rspamd_log->throttling_time = time (NULL);
- }
- else if (errno == EPIPE || errno == EBADF) {
- /* We write to some pipe and it disappears, disable logging or we has opened bad file descriptor */
- rspamd_log->enabled = FALSE;
- }
+ /* Rare case */
+ rspamd_log->throttling = TRUE;
+ rspamd_log->throttling_time = time (NULL);
}
- else if (rspamd_log->throttling) {
- rspamd_log->throttling = FALSE;
+ else if (errno == EPIPE || errno == EBADF) {
+ /* We write to some pipe and it disappears, disable logging or we has opened bad file descriptor */
+ rspamd_log->enabled = FALSE;
}
}
+ else if (rspamd_log->throttling) {
+ rspamd_log->throttling = FALSE;
+ }
}
static void
@@ -807,7 +805,7 @@ syslog_log_function (const gchar *module, const gchar *id,
unsigned i;
gint syslog_level;
- if (!rspamd_log->enabled) {
+ if (!(level_flags & RSPAMD_LOG_FORCED) && !rspamd_log->enabled) {
return;
}
/* Detect level */
@@ -850,12 +848,12 @@ file_log_function (const gchar *module, const gchar *id,
gboolean got_time = FALSE;
rspamd_logger_t *rspamd_log = arg;
- if (!rspamd_log->enabled) {
+ if (!(level_flags & RSPAMD_LOG_FORCED) && !rspamd_log->enabled) {
return;
}
/* Check throttling due to write errors */
- if (rspamd_log->throttling) {
+ if (!(level_flags & RSPAMD_LOG_FORCED) && rspamd_log->throttling) {
now = time (NULL);
if (rspamd_log->throttling_time != now) {
rspamd_log->throttling_time = now;