aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c6
-rw-r--r--src/symbols_cache.c95
-rw-r--r--src/symbols_cache.h12
3 files changed, 60 insertions, 53 deletions
diff --git a/src/main.c b/src/main.c
index 14a4988ee..43c0a07e6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -693,7 +693,7 @@ static void
init_cfg_cache (struct config_file *cfg)
{
- if (!init_symbols_cache (cfg->cfg_pool, cfg->cache, cfg, cfg->cache_filename)) {
+ if (!init_symbols_cache (cfg->cfg_pool, cfg->cache, cfg, cfg->cache_filename, FALSE)) {
exit (EXIT_FAILURE);
}
}
@@ -705,7 +705,7 @@ print_symbols_cache (struct config_file *cfg)
struct cache_item *item;
gint i;
- if (!init_symbols_cache (cfg->cfg_pool, cfg->cache, cfg, cfg->cache_filename)) {
+ if (!init_symbols_cache (cfg->cfg_pool, cfg->cache, cfg, cfg->cache_filename, TRUE)) {
exit (EXIT_FAILURE);
}
if (cfg->cache) {
@@ -869,7 +869,7 @@ main (gint argc, gchar **argv, gchar **env)
/* Insert classifiers symbols */
(void)insert_classifier_symbols (rspamd->cfg);
- if (! validate_cache (rspamd->cfg->cache, rspamd->cfg, TRUE)) {
+ if (! validate_cache (rspamd->cfg->cache, rspamd->cfg, FALSE)) {
res = FALSE;
}
if (dump_vars) {
diff --git a/src/symbols_cache.c b/src/symbols_cache.c
index e6bd9a2ce..0c4891df2 100644
--- a/src/symbols_cache.c
+++ b/src/symbols_cache.c
@@ -504,7 +504,8 @@ free_cache (gpointer arg)
}
gboolean
-init_symbols_cache (memory_pool_t * pool, struct symbols_cache *cache, struct config_file *cfg, const gchar *filename)
+init_symbols_cache (memory_pool_t * pool, struct symbols_cache *cache, struct config_file *cfg,
+ const gchar *filename, gboolean ignore_checksum)
{
struct stat st;
gint fd;
@@ -553,23 +554,55 @@ init_symbols_cache (memory_pool_t * pool, struct symbols_cache *cache, struct co
}
}
- /* Calculate checksum */
- cksum = get_mem_cksum (cache);
- if (cksum == NULL) {
- msg_err ("cannot calculate checksum for symbols");
- close (fd);
- return FALSE;
- }
+ if (!ignore_checksum) {
+ /* Calculate checksum */
+ cksum = get_mem_cksum (cache);
+ if (cksum == NULL) {
+ msg_err ("cannot calculate checksum for symbols");
+ close (fd);
+ return FALSE;
+ }
- cklen = g_checksum_type_get_length (G_CHECKSUM_SHA1);
- mem_sum = g_malloc (cklen);
+ cklen = g_checksum_type_get_length (G_CHECKSUM_SHA1);
+ mem_sum = g_malloc (cklen);
- g_checksum_get_digest (cksum, mem_sum, &cklen);
- /* Now try to read file sum */
- if (lseek (fd, -(cklen), SEEK_END) == -1) {
- if (errno == EINVAL) {
- /* Try to create file */
- msg_info ("recreate cache file");
+ g_checksum_get_digest (cksum, mem_sum, &cklen);
+ /* Now try to read file sum */
+ if (lseek (fd, -(cklen), SEEK_END) == -1) {
+ if (errno == EINVAL) {
+ /* Try to create file */
+ msg_info ("recreate cache file");
+ if ((fd = open (filename, O_RDWR | O_TRUNC | O_CREAT, S_IWUSR | S_IRUSR)) == -1) {
+ msg_info ("cannot create file %s, error %d, %s", filename, errno, strerror (errno));
+ return FALSE;
+ }
+ else {
+ return create_cache_file (cache, filename, fd, pool);
+ }
+ }
+ close (fd);
+ g_free (mem_sum);
+ g_checksum_free (cksum);
+ msg_err ("cannot seek to read checksum, %d, %s", errno, strerror (errno));
+ return FALSE;
+ }
+ file_sum = g_malloc (cklen);
+ if (read (fd, file_sum, cklen) == -1) {
+ close (fd);
+ g_free (mem_sum);
+ g_free (file_sum);
+ g_checksum_free (cksum);
+ msg_err ("cannot read checksum, %d, %s", errno, strerror (errno));
+ return FALSE;
+ }
+
+ if (memcmp (file_sum, mem_sum, cklen) != 0) {
+ close (fd);
+ g_free (mem_sum);
+ g_free (file_sum);
+ g_checksum_free (cksum);
+ msg_info ("checksum mismatch, recreating file");
+ /* Reopen with rw permissions */
if ((fd = open (filename, O_RDWR | O_TRUNC | O_CREAT, S_IWUSR | S_IRUSR)) == -1) {
msg_info ("cannot create file %s, error %d, %s", filename, errno, strerror (errno));
return FALSE;
@@ -578,41 +611,11 @@ init_symbols_cache (memory_pool_t * pool, struct symbols_cache *cache, struct co
return create_cache_file (cache, filename, fd, pool);
}
}
- close (fd);
- g_free (mem_sum);
- g_checksum_free (cksum);
- msg_err ("cannot seek to read checksum, %d, %s", errno, strerror (errno));
- return FALSE;
- }
- file_sum = g_malloc (cklen);
- if (read (fd, file_sum, cklen) == -1) {
- close (fd);
- g_free (mem_sum);
- g_free (file_sum);
- g_checksum_free (cksum);
- msg_err ("cannot read checksum, %d, %s", errno, strerror (errno));
- return FALSE;
- }
- if (memcmp (file_sum, mem_sum, cklen) != 0) {
- close (fd);
g_free (mem_sum);
g_free (file_sum);
g_checksum_free (cksum);
- msg_info ("checksum mismatch, recreating file");
- /* Reopen with rw permissions */
- if ((fd = open (filename, O_RDWR | O_TRUNC | O_CREAT, S_IWUSR | S_IRUSR)) == -1) {
- msg_info ("cannot create file %s, error %d, %s", filename, errno, strerror (errno));
- return FALSE;
- }
- else {
- return create_cache_file (cache, filename, fd, pool);
- }
}
-
- g_free (mem_sum);
- g_free (file_sum);
- g_checksum_free (cksum);
/* MMap cache file and copy saved_cache structures */
res = mmap_cache_file (cache, fd, pool);
memory_pool_add_destructor (pool, (pool_destruct_func)free_cache, cache);
diff --git a/src/symbols_cache.h b/src/symbols_cache.h
index 6d41f7d7f..d84b2492b 100644
--- a/src/symbols_cache.h
+++ b/src/symbols_cache.h
@@ -73,7 +73,8 @@ struct symbols_cache {
/**
* Load symbols cache from file, must be called _after_ init_symbols_cache
*/
-gboolean init_symbols_cache (memory_pool_t *pool, struct symbols_cache *cache, struct config_file *cfg, const gchar *filename);
+gboolean init_symbols_cache (memory_pool_t *pool, struct symbols_cache *cache, struct config_file *cfg,
+ const gchar *filename, gboolean ignore_checksum);
/**
* Register function for symbols parsing
@@ -81,7 +82,8 @@ gboolean init_symbols_cache (memory_pool_t *pool, struct symbols_cache *cache, s
* @param func pointer to handler
* @param user_data pointer to user_data
*/
-void register_symbol (struct symbols_cache **cache, const gchar *name, double weight, symbol_func_t func, gpointer user_data);
+void register_symbol (struct symbols_cache **cache, const gchar *name, double weight,
+ symbol_func_t func, gpointer user_data);
/**
@@ -96,7 +98,8 @@ void register_virtual_symbol (struct symbols_cache **cache, const gchar *name, d
* @param func pointer to handler
* @param user_data pointer to user_data
*/
-void register_callback_symbol (struct symbols_cache **cache, const gchar *name, double weight, symbol_func_t func, gpointer user_data);
+void register_callback_symbol (struct symbols_cache **cache, const gchar *name, double weight,
+ symbol_func_t func, gpointer user_data);
/**
* Register function for symbols parsing with strict priority
@@ -104,7 +107,8 @@ void register_callback_symbol (struct symbols_cache **cache, const gchar *name,
* @param func pointer to handler
* @param user_data pointer to user_data
*/
-void register_callback_symbol_priority (struct symbols_cache **cache, const gchar *name, double weight, gint priority, symbol_func_t func, gpointer user_data);
+void register_callback_symbol_priority (struct symbols_cache **cache, const gchar *name, double weight,
+ gint priority, symbol_func_t func, gpointer user_data);
/**
* Register function for dynamic symbols parsing