aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-22 16:28:52 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-22 16:28:52 +0100
commit04a539f1333f7dfc3b1d6799b16956b576cad3cb (patch)
treeb9215f2fe8c1fc5874be4922980764538d08d66f
parentca1b4f4d477fbc52df8ac5e399949611e8351a8d (diff)
downloadrspamd-04a539f1333f7dfc3b1d6799b16956b576cad3cb.tar.gz
rspamd-04a539f1333f7dfc3b1d6799b16956b576cad3cb.zip
[Feature] Add a concept of ignored symbols to avoid race conditions
-rw-r--r--src/libmime/filter.h6
-rw-r--r--src/libserver/composites.c2
-rw-r--r--src/libserver/protocol.c6
-rw-r--r--src/libserver/roll_history.c4
-rw-r--r--src/libserver/task.c6
-rw-r--r--src/lua/lua_task.c29
6 files changed, 37 insertions, 16 deletions
diff --git a/src/libmime/filter.h b/src/libmime/filter.h
index 798e5305f..8d90ef87a 100644
--- a/src/libmime/filter.h
+++ b/src/libmime/filter.h
@@ -19,6 +19,11 @@ struct rspamd_symbol_option {
struct rspamd_symbol_option *prev, *next;
};
+enum rspamd_symbol_result_flags {
+ RSPAMD_SYMBOL_RESULT_NORMAL = 0,
+ RSPAMD_SYMBOL_RESULT_IGNORED = (1 << 0)
+};
+
/**
* Rspamd symbol
*/
@@ -29,6 +34,7 @@ struct rspamd_symbol_result {
const gchar *name;
struct rspamd_symbol *sym; /**< symbol configuration */
guint nshots;
+ enum rspamd_symbol_result_flags flags;
};
/**
diff --git a/src/libserver/composites.c b/src/libserver/composites.c
index 67ed71149..2ac820990 100644
--- a/src/libserver/composites.c
+++ b/src/libserver/composites.c
@@ -424,7 +424,7 @@ composites_remove_symbols (gpointer key, gpointer value, gpointer data)
if (has_valid_op) {
if (want_remove_symbol || want_forced) {
- g_hash_table_remove (cd->metric_res->symbols, key);
+ rd->ms->flags |= RSPAMD_SYMBOL_RESULT_IGNORED;
msg_debug_composites ("remove symbol %s", key);
}
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c
index 51b2fa0e5..0e4f9cb0c 100644
--- a/src/libserver/protocol.c
+++ b/src/libserver/protocol.c
@@ -970,8 +970,10 @@ rspamd_metric_result_ucl (struct rspamd_task *task,
while (g_hash_table_iter_next (&hiter, &h, &v)) {
sym = (struct rspamd_symbol_result *)v;
- sobj = rspamd_metric_symbol_ucl (task, sym);
- ucl_object_insert_key (obj, sobj, h, 0, false);
+ if (!(sym->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) {
+ sobj = rspamd_metric_symbol_ucl (task, sym);
+ ucl_object_insert_key (obj, sobj, h, 0, false);
+ }
}
if (task->cmd == CMD_CHECK_V2) {
diff --git a/src/libserver/roll_history.c b/src/libserver/roll_history.c
index 04f2da0c6..6dbd4d338 100644
--- a/src/libserver/roll_history.c
+++ b/src/libserver/roll_history.c
@@ -77,6 +77,10 @@ roll_history_symbols_callback (gpointer key, gpointer value, void *user_data)
struct rspamd_symbol_result *s = value;
guint wr;
+ if (s->flags & RSPAMD_SYMBOL_RESULT_IGNORED) {
+ return;
+ }
+
if (cb->remain > 0) {
wr = rspamd_snprintf (cb->pos, cb->remain, "%s, ", s->name);
cb->pos += wr;
diff --git a/src/libserver/task.c b/src/libserver/task.c
index f626a8c7b..d881c6897 100644
--- a/src/libserver/task.c
+++ b/src/libserver/task.c
@@ -1087,7 +1087,11 @@ rspamd_task_log_metric_res (struct rspamd_task *task,
sorted_symbols = g_ptr_array_sized_new (g_hash_table_size (mres->symbols));
while (g_hash_table_iter_next (&it, &k, &v)) {
- g_ptr_array_add (sorted_symbols, v);
+ sym = v;
+
+ if (!(sym->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) {
+ g_ptr_array_add (sorted_symbols, v);
+ }
}
g_ptr_array_sort (sorted_symbols, rspamd_task_compare_log_sym);
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index ca55609a7..db5bd090a 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -3309,11 +3309,13 @@ lua_task_get_symbols (lua_State *L)
while (g_hash_table_iter_next (&it, &k, &v)) {
s = v;
- lua_pushstring (L, k);
- lua_rawseti (L, -3, i);
- lua_pushnumber (L, s->score);
- lua_rawseti (L, -2, i);
- i ++;
+ if (!(s->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) {
+ lua_pushstring (L, k);
+ lua_rawseti (L, -3, i);
+ lua_pushnumber (L, s->score);
+ lua_rawseti (L, -2, i);
+ i++;
+ }
}
}
else {
@@ -3384,14 +3386,17 @@ lua_task_get_symbols_numeric (lua_State *L)
g_hash_table_iter_init (&it, mres->symbols);
while (g_hash_table_iter_next (&it, &k, &v)) {
- id = rspamd_symbols_cache_find_symbol (task->cfg->cache,
- k);
s = v;
- lua_pushnumber (L, id);
- lua_rawseti (L, -3, i);
- lua_pushnumber (L, s->score);
- lua_rawseti (L, -2, i);
- i ++;
+
+ if (!(s->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) {
+ id = rspamd_symbols_cache_find_symbol (task->cfg->cache,
+ k);
+ lua_pushnumber (L, id);
+ lua_rawseti (L, -3, i);
+ lua_pushnumber (L, s->score);
+ lua_rawseti (L, -2, i);
+ i++;
+ }
}
}
else {