]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Rework system of workers' flags
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 4 Apr 2016 13:32:18 +0000 (14:32 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 4 Apr 2016 13:32:18 +0000 (14:32 +0100)
src/controller.c
src/fuzzy_storage.c
src/hs_helper.c
src/http_proxy.c
src/lua_worker.c
src/rspamd.c
src/rspamd.h
src/smtp_proxy.c
src/worker.c

index b20e6a8f7d5d5821ecfc5f7cc750f654adbb69d8..6aefe071976f72c906090722617f3f3015558200 100644 (file)
@@ -106,10 +106,7 @@ worker_t controller_worker = {
        "controller",                   /* Name */
        init_controller_worker,         /* Init function */
        start_controller_worker,        /* Start function */
-       TRUE,                   /* Has socket */
-       TRUE,                   /* Non unique */
-       FALSE,                  /* Non threaded */
-       TRUE,                   /* Killable */
+       RSPAMD_WORKER_HAS_SOCKET | RSPAMD_WORKER_KILLABLE,
        SOCK_STREAM,            /* TCP socket */
        RSPAMD_WORKER_VER       /* Version info */
 };
index 9ca032e22de788e0a3c69b28ecb5ba4453370071..b37d6766cce3291fae4cb9b5eb8ed1f9fcb92fbd 100644 (file)
@@ -49,15 +49,12 @@ gpointer init_fuzzy (struct rspamd_config *cfg);
 void start_fuzzy (struct rspamd_worker *worker);
 
 worker_t fuzzy_worker = {
-       "fuzzy",                    /* Name */
-       init_fuzzy,                 /* Init function */
-       start_fuzzy,                /* Start function */
-       TRUE,                       /* No socket */
-       FALSE,                      /* Unique */
-       FALSE,                      /* Threaded */
-       FALSE,                      /* Non killable */
-       SOCK_DGRAM,                 /* UDP socket */
-       RSPAMD_WORKER_VER           /* Version info */
+               "fuzzy",                    /* Name */
+               init_fuzzy,                 /* Init function */
+               start_fuzzy,                /* Start function */
+               RSPAMD_WORKER_HAS_SOCKET,
+               SOCK_DGRAM,                 /* UDP socket */
+               RSPAMD_WORKER_VER           /* Version info */
 };
 
 /* For evtimer */
index 5f955561d50dea1b31ed40d47dbbd37b75881c76..5885461aa62b0ca7285c215fb22fb1b2183c489d 100644 (file)
@@ -32,10 +32,7 @@ worker_t hs_helper_worker = {
                "hs_helper",                /* Name */
                init_hs_helper,             /* Init function */
                start_hs_helper,            /* Start function */
-               FALSE,                      /* No socket */
-               TRUE,                       /* Unique */
-               FALSE,                      /* Non threaded */
-               TRUE,                       /* Killable */
+               RSPAMD_WORKER_UNIQUE|RSPAMD_WORKER_KILLABLE|RSPAMD_WORKER_ALWAYS_START,
                SOCK_STREAM,                /* TCP socket */
                RSPAMD_WORKER_VER           /* Version info */
 };
index f0680fcb0ac54dc199dd634660e498207669c4ec..3ad821f9675d8338e26206f6d61f6ab59242193b 100644 (file)
@@ -38,10 +38,7 @@ worker_t http_proxy_worker = {
        "http_proxy",               /* Name */
        init_http_proxy,            /* Init function */
        start_http_proxy,           /* Start function */
-       TRUE,                       /* Has socket */
-       FALSE,                      /* Non unique */
-       FALSE,                      /* Non threaded */
-       TRUE,                       /* Killable */
+       RSPAMD_WORKER_HAS_SOCKET | RSPAMD_WORKER_KILLABLE,
        SOCK_STREAM,                /* TCP socket */
        RSPAMD_WORKER_VER
 };
index 799379c00476af9949ea92f385df284358a8c385..ea876cec5e26b18b0f109192f7b31529f78f5155 100644 (file)
@@ -42,10 +42,7 @@ worker_t lua_worker = {
        "lua",                  /* Name */
        init_lua_worker,        /* Init function */
        start_lua_worker,       /* Start function */
-       TRUE,                   /* Has socket */
-       FALSE,                  /* Non unique */
-       FALSE,                  /* Non threaded */
-       TRUE,                   /* Killable */
+       RSPAMD_WORKER_HAS_SOCKET | RSPAMD_WORKER_KILLABLE,
        SOCK_STREAM,            /* TCP socket */
        RSPAMD_WORKER_VER       /* Version info */
 };
index c47056562e53b2693caada547bbc2a03dbe161b7..43b79a105ca0d337971e3ed8d1504f249e5b01cf 100644 (file)
@@ -432,7 +432,7 @@ spawn_worker_type (struct rspamd_main *rspamd_main, struct event_base *ev_base,
 {
        gint i;
 
-       if (cf->worker->unique) {
+       if (!(cf->worker->flags & RSPAMD_WORKER_UNIQUE)) {
                if (cf->count > 1) {
                        msg_warn_main (
                                        "cannot spawn more than 1 %s worker, so spawn one",
@@ -440,7 +440,7 @@ spawn_worker_type (struct rspamd_main *rspamd_main, struct event_base *ev_base,
                }
                rspamd_fork_worker (rspamd_main, cf, 0, ev_base);
        }
-       else if (cf->worker->threaded) {
+       else if (cf->worker->flags & RSPAMD_WORKER_THREADED) {
                rspamd_fork_worker (rspamd_main, cf, 0, ev_base);
        }
        else {
@@ -478,7 +478,7 @@ spawn_workers (struct rspamd_main *rspamd_main, struct event_base *ev_base)
                        msg_err_main ("type of worker is unspecified, skip spawning");
                }
                else {
-                       if (cf->worker->has_socket) {
+                       if (cf->worker->flags & RSPAMD_WORKER_HAS_SOCKET) {
                                LL_FOREACH (cf->bind_conf, bcf) {
                                        key = make_listen_key (bcf);
                                        if ((p =
@@ -588,7 +588,7 @@ wait_for_workers (gpointer key, gpointer value, gpointer unused)
 
        if (waitpid (w->pid, &res, WNOHANG) <= 0) {
                if (term_attempts == 0) {
-                       if (w->cf->worker->killable) {
+                       if (w->cf->worker->flags & RSPAMD_WORKER_KILLABLE) {
                                msg_info_main ("terminate worker %P with SIGKILL", w->pid);
                                kill (w->pid, SIGKILL);
                        }
index 5fb40861c064848226f347c799de92f17b0d2317..90a4b376269b098672395b9a83a6129726724e04 100644 (file)
@@ -118,7 +118,7 @@ struct module_ctx {
 #endif
 
 #define RSPAMD_CUR_MODULE_VERSION 0x1
-#define RSPAMD_CUR_WORKER_VERSION 0x1
+#define RSPAMD_CUR_WORKER_VERSION 0x2
 
 #define RSPAMD_FEATURES \
                RSPAMD_FEATURE_HYPERSCAN RSPAMD_FEATURE_PCRE2 \
@@ -148,14 +148,19 @@ 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),
+};
+
 typedef struct worker_s {
        const gchar *name;
        gpointer (*worker_init_func)(struct rspamd_config *cfg);
        void (*worker_start_func)(struct rspamd_worker *worker);
-       gboolean has_socket;
-       gboolean unique;
-       gboolean threaded;
-       gboolean killable;
+       enum rspamd_worker_flags flags;
        gint listen_type;
        guint worker_version;
        guint64 rspamd_version;
index dca0359936cc59b3b5d460440ca27f2ebade6a3c..3f9444b06341e143241999d4b74b28d7a7325f71 100644 (file)
@@ -43,10 +43,7 @@ worker_t smtp_proxy_worker = {
        "smtp_proxy",               /* Name */
        init_smtp_proxy,            /* Init function */
        start_smtp_proxy,           /* Start function */
-       TRUE,                       /* Has socket */
-       FALSE,                      /* Non unique */
-       FALSE,                      /* Non threaded */
-       TRUE,                       /* Killable */
+       RSPAMD_WORKER_HAS_SOCKET | RSPAMD_WORKER_KILLABLE,
        SOCK_STREAM,                /* TCP socket */
        RSPAMD_WORKER_VER           /* Version info */
 };
index 3939db7022e9e6c48063ac4d19651075f057369a..a4ef7a81ab293f3197158b585857fa5428f6dd87 100644 (file)
@@ -45,15 +45,12 @@ gpointer init_worker (struct rspamd_config *cfg);
 void start_worker (struct rspamd_worker *worker);
 
 worker_t normal_worker = {
-       "normal",                   /* Name */
-       init_worker,                /* Init function */
-       start_worker,               /* Start function */
-       TRUE,                       /* Has socket */
-       FALSE,                      /* Non unique */
-       FALSE,                      /* Non threaded */
-       TRUE,                       /* Killable */
-       SOCK_STREAM,                /* TCP socket */
-       RSPAMD_WORKER_VER           /* Version info */
+               "normal",                   /* Name */
+               init_worker,                /* Init function */
+               start_worker,               /* Start function */
+               RSPAMD_WORKER_HAS_SOCKET|RSPAMD_WORKER_KILLABLE,
+               SOCK_STREAM,                /* TCP socket */
+               RSPAMD_WORKER_VER           /* Version info */
 };
 
 #define msg_err_ctx(...) rspamd_default_log_function(G_LOG_LEVEL_CRITICAL, \