commit 91c623b: [Minor] Fix id priorities application

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Feb 3 13:42:06 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-02-03 13:37:08 +0000
URL: https://github.com/rspamd/rspamd/commit/91c623b74c85b242c856dfac1bdc8dd7651792bf (HEAD -> master)

[Minor] Fix id priorities application

---
 src/lua/lua_task.c           |  7 +++++--
 src/plugins/lua/settings.lua | 30 ++++++++++++++++++++++--------
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 3855c3cc4..16aa15624 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -5593,8 +5593,11 @@ lua_task_set_settings_id (lua_State *L)
 
 		if (task->settings_elt) {
 			if (task->settings_elt->id != id) {
-				return luaL_error (L, "settings id has been already set to %d (%s)",
-						task->settings_elt->id, task->settings_elt->name);
+				return luaL_error (L, "settings id has been already set to %d (%s); "
+						  "trying to set it to %d",
+						task->settings_elt->id,
+						task->settings_elt->name,
+						id);
 			}
 		}
 		else {
diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua
index be22bf1e5..bc91bf4c8 100644
--- a/src/plugins/lua/settings.lua
+++ b/src/plugins/lua/settings.lua
@@ -253,6 +253,18 @@ local function check_ip_setting(expected, ip)
   return false
 end
 
+local function priority_to_string(pri)
+  if pri then
+    if pri >= 3 then
+      return "high"
+    elseif pri >= 2 then
+      return "medium"
+    end
+  end
+
+  return "low"
+end
+
 -- Check limit for a task
 local function check_settings(task)
   local function check_specific_setting(rule, matched)
@@ -296,20 +308,21 @@ local function check_settings(task)
     if query_apply then
       if id_elt then
         apply_settings(task, query_apply, id_elt.id)
-        rspamd_logger.infox(task, "applied settings id %s(%s)",
-            id_elt.name, id_elt.id)
+        rspamd_logger.infox(task, "applied settings id %s(%s); priority %s",
+            id_elt.name, id_elt.id, priority_to_string(priority))
       else
         apply_settings(task, query_apply, nil)
-        rspamd_logger.infox(task, "applied settings from query")
+        rspamd_logger.infox(task, "applied settings from query; priority %s",
+            priority_to_string(priority))
       end
     end
   end
 
   local min_pri = 1
   if query_apply then
-    if priority > min_pri then
-      -- Do not check lower priorities
-      min_pri = priority
+    if priority >= min_pri then
+      -- Do not check lower or equal priorities
+      min_pri = priority + 1
     end
 
     if priority > max_pri then
@@ -347,10 +360,11 @@ local function check_settings(task)
               if not cached or not cached.settings or not cached.settings.apply then
                 rspamd_logger.errx(task, 'unregistered settings id found: %s!', s.rule.id)
               else
-                rspamd_logger.infox(task, "<%s> apply static settings %s (id = %s); %s matched",
+                rspamd_logger.infox(task, "<%s> apply static settings %s (id = %s); %s matched; priority %s",
                     task:get_message_id(),
                     cached.name, s.rule.id,
-                    table.concat(matched, ','))
+                    table.concat(matched, ','),
+                    priority_to_string(pri))
                 apply_settings(task, cached.settings.apply, s.rule.id)
               end
 


More information about the Commits mailing list