]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Allow to detect worker's scanner flag from lua
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 26 Feb 2018 15:45:33 +0000 (15:45 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 26 Feb 2018 15:45:33 +0000 (15:45 +0000)
src/controller.c
src/libserver/symbols_cache.c
src/libserver/worker_util.c
src/libserver/worker_util.h
src/lua/lua_common.c
src/rspamd.h
src/rspamd_proxy.c
src/worker.c

index 61e00fdd58b6acef3f55af92fab3f6ec1dc535b8..0443062a11c37910923008d5f71832b2c8aa5fba 100644 (file)
@@ -117,7 +117,8 @@ worker_t controller_worker = {
        "controller",                   /* Name */
        init_controller_worker,         /* Init function */
        start_controller_worker,        /* Start function */
-       RSPAMD_WORKER_HAS_SOCKET | RSPAMD_WORKER_KILLABLE,
+       RSPAMD_WORKER_HAS_SOCKET | RSPAMD_WORKER_KILLABLE |
+                       RSPAMD_WORKER_SCANNER | RSPAMD_WORKER_CONTROLLER,
        RSPAMD_WORKER_SOCKET_TCP,       /* TCP socket */
        RSPAMD_WORKER_VER       /* Version info */
 };
index b890578ed6c34a3417548d53bf769f6e785c4b89..4c15184d46280680dde5dc4beadb7cb265442343 100644 (file)
@@ -1308,7 +1308,7 @@ rspamd_symbols_cache_check_symbol (struct rspamd_task *task,
                                                diff);
                        }
 
-                       if (rspamd_worker_is_normal (task->worker)) {
+                       if (rspamd_worker_is_scanner (task->worker)) {
                                rspamd_set_counter (item->cd, diff);
                        }
 
@@ -2026,7 +2026,7 @@ rspamd_symbols_cache_resort_cb (gint fd, short what, gpointer ud)
        double_to_tv (tm, &tv);
        event_add (&cbdata->resort_ev, &tv);
 
-       if (rspamd_worker_is_normal (cbdata->w)) {
+       if (rspamd_worker_is_scanner (cbdata->w)) {
                rspamd_mempool_lock_mutex (cache->mtx);
 
                /* Gather stats from shared execution times */
index 7c92dc3596b767ed5b18d9758b5889dba3184570..f6bc78aaa767dd542f88ccc0567a1a96f50c15c8 100644 (file)
@@ -588,6 +588,7 @@ rspamd_fork_worker (struct rspamd_main *rspamd_main,
        wrk->srv = rspamd_main;
        wrk->type = cf->type;
        wrk->cf = cf;
+       wrk->flags = cf->worker->flags;
        REF_RETAIN (cf);
        wrk->index = index;
        wrk->ctx = cf->ctx;
@@ -740,19 +741,11 @@ rspamd_hard_terminate (struct rspamd_main *rspamd_main)
 }
 
 gboolean
-rspamd_worker_is_normal (struct rspamd_worker *w)
+rspamd_worker_is_scanner (struct rspamd_worker *w)
 {
-       static GQuark normal_quark = (GQuark)0;
 
        if (w) {
-               if (normal_quark) {
-                       return w->type == normal_quark;
-               }
-               else {
-                       normal_quark = g_quark_from_static_string ("normal");
-               }
-
-               return w->type == normal_quark;
+               return !!(w->flags & RSPAMD_WORKER_SCANNER);
        }
 
        return FALSE;
index 14ca3ff2a1c1ce32a4148c412d48705b5973d01a..179907ee4012151f5fc68c6f89e85f80e9e86c79 100644 (file)
@@ -147,7 +147,7 @@ void rspamd_hard_terminate (struct rspamd_main *rspamd_main) G_GNUC_NORETURN;
  * @param w
  * @return
  */
-gboolean rspamd_worker_is_normal (struct rspamd_worker *w);
+gboolean rspamd_worker_is_scanner (struct rspamd_worker *w);
 
 /**
  * Creates new session cache
index 15e26bedaf67ea345bcbb3ddd6f41d80c85cf4e3..f61fa6d0bdabb8955a64a6feac594435cf053d8e 100644 (file)
@@ -37,6 +37,7 @@ LUA_FUNCTION_DEF (worker, get_name);
 LUA_FUNCTION_DEF (worker, get_stat);
 LUA_FUNCTION_DEF (worker, get_index);
 LUA_FUNCTION_DEF (worker, get_pid);
+LUA_FUNCTION_DEF (worker, is_scanner);
 LUA_FUNCTION_DEF (worker, spawn_process);
 
 const luaL_reg worker_reg[] = {
@@ -45,6 +46,7 @@ const luaL_reg worker_reg[] = {
        LUA_INTERFACE_DEF (worker, get_index),
        LUA_INTERFACE_DEF (worker, get_pid),
        LUA_INTERFACE_DEF (worker, spawn_process),
+       LUA_INTERFACE_DEF (worker, is_scanner),
        {"__tostring", rspamd_lua_class_tostring},
        {NULL, NULL}
 };
@@ -1431,6 +1433,22 @@ lua_worker_get_pid (lua_State *L)
        return 1;
 }
 
+
+static gint
+lua_worker_is_scanner (lua_State *L)
+{
+       struct rspamd_worker *w = lua_check_worker (L, 1);
+
+       if (w) {
+               lua_pushboolean (L, rspamd_worker_is_scanner (w));
+       }
+       else {
+               return luaL_error (L, "invalid arguments");
+       }
+
+       return 1;
+}
+
 struct rspamd_lua_process_cbdata {
        gint sp[2];
        gint func_cbref;
index adc2576b4f8e1c826780e1301ceb1dae78b73a85..4fdc626da052f9d5fe0ff4e0ba839022881cd450 100644 (file)
 #define CR '\r'
 #define LF '\n'
 
+enum rspamd_worker_flags {
+       RSPAMD_WORKER_HAS_SOCKET = (1 << 0),
+       RSPAMD_WORKER_UNIQUE = (1 << 1),
+       RSPAMD_WORKER_THREADED = (1 << 2),
+       RSPAMD_WORKER_KILLABLE = (1 << 3),
+       RSPAMD_WORKER_ALWAYS_START = (1 << 4),
+       RSPAMD_WORKER_SCANNER = (1 << 5),
+       RSPAMD_WORKER_CONTROLLER = (1 << 6),
+};
+
+
 /**
  * Worker process structure
  */
@@ -68,6 +79,7 @@ struct rspamd_worker {
        GList *accept_events;           /**< socket events                                                                      */
        struct rspamd_worker_conf *cf;  /**< worker config data                                                         */
        gpointer ctx;                   /**< worker's specific data                                                     */
+       enum rspamd_worker_flags flags; /**< worker's flags                                                                     */
        gint control_pipe[2];           /**< control pipe. [0] is used by main process,
                                                           [1] is used by a worker                      */
        gint srv_pipe[2];               /**< used by workers to request something from the
@@ -180,14 +192,6 @@ typedef struct module_s {
        const gchar *rspamd_features;
 } module_t;
 
-enum rspamd_worker_flags {
-       RSPAMD_WORKER_HAS_SOCKET = (1 << 0),
-       RSPAMD_WORKER_UNIQUE = (1 << 1),
-       RSPAMD_WORKER_THREADED = (1 << 2),
-       RSPAMD_WORKER_KILLABLE = (1 << 3),
-       RSPAMD_WORKER_ALWAYS_START = (1 << 4),
-};
-
 enum rspamd_worker_socket_type {
        RSPAMD_WORKER_SOCKET_NONE = 0,
        RSPAMD_WORKER_SOCKET_TCP = (1 << 0),
index 6dedffff371168ee93a013651f5f480e1b5e7ec7..a7c20e34b63b2d8fdefacdc1c5d3b324b8977e75 100644 (file)
@@ -72,7 +72,7 @@ worker_t rspamd_proxy_worker = {
        "rspamd_proxy",               /* Name */
        init_rspamd_proxy,            /* Init function */
        start_rspamd_proxy,           /* Start function */
-       RSPAMD_WORKER_HAS_SOCKET | RSPAMD_WORKER_KILLABLE,
+       RSPAMD_WORKER_HAS_SOCKET | RSPAMD_WORKER_KILLABLE | RSPAMD_WORKER_SCANNER,
        RSPAMD_WORKER_SOCKET_TCP,    /* TCP socket */
        RSPAMD_WORKER_VER
 };
index fc71be1be0facef93acc1ec76ee1df5243baed30..6b02b5753ee5c0826a4eea0c38f4c5daef19386e 100644 (file)
@@ -51,7 +51,7 @@ worker_t normal_worker = {
                "normal",                   /* Name */
                init_worker,                /* Init function */
                start_worker,               /* Start function */
-               RSPAMD_WORKER_HAS_SOCKET|RSPAMD_WORKER_KILLABLE,
+               RSPAMD_WORKER_HAS_SOCKET|RSPAMD_WORKER_KILLABLE|RSPAMD_WORKER_SCANNER,
                RSPAMD_WORKER_SOCKET_TCP,   /* TCP socket */
                RSPAMD_WORKER_VER           /* Version info */
 };