aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-04 14:32:18 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-04 14:32:18 +0100
commitc442adeaa297aa760fe7c4fba63c1324056fcc79 (patch)
treef401b93691418a89d791e4174d2d41d1d8a1185b
parent007c2befbe517ac6d44830a7900c3ac3fdf6d634 (diff)
downloadrspamd-c442adeaa297aa760fe7c4fba63c1324056fcc79.tar.gz
rspamd-c442adeaa297aa760fe7c4fba63c1324056fcc79.zip
[Feature] Rework system of workers' flags
-rw-r--r--src/controller.c5
-rw-r--r--src/fuzzy_storage.c15
-rw-r--r--src/hs_helper.c5
-rw-r--r--src/http_proxy.c5
-rw-r--r--src/lua_worker.c5
-rw-r--r--src/rspamd.c8
-rw-r--r--src/rspamd.h15
-rw-r--r--src/smtp_proxy.c5
-rw-r--r--src/worker.c15
9 files changed, 31 insertions, 47 deletions
diff --git a/src/controller.c b/src/controller.c
index b20e6a8f7..6aefe0719 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -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 */
};
diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c
index 9ca032e22..b37d6766c 100644
--- a/src/fuzzy_storage.c
+++ b/src/fuzzy_storage.c
@@ -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 */
diff --git a/src/hs_helper.c b/src/hs_helper.c
index 5f955561d..5885461aa 100644
--- a/src/hs_helper.c
+++ b/src/hs_helper.c
@@ -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 */
};
diff --git a/src/http_proxy.c b/src/http_proxy.c
index f0680fcb0..3ad821f96 100644
--- a/src/http_proxy.c
+++ b/src/http_proxy.c
@@ -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
};
diff --git a/src/lua_worker.c b/src/lua_worker.c
index 799379c00..ea876cec5 100644
--- a/src/lua_worker.c
+++ b/src/lua_worker.c
@@ -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 */
};
diff --git a/src/rspamd.c b/src/rspamd.c
index c47056562..43b79a105 100644
--- a/src/rspamd.c
+++ b/src/rspamd.c
@@ -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);
}
diff --git a/src/rspamd.h b/src/rspamd.h
index 5fb40861c..90a4b3762 100644
--- a/src/rspamd.h
+++ b/src/rspamd.h
@@ -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;
diff --git a/src/smtp_proxy.c b/src/smtp_proxy.c
index dca035993..3f9444b06 100644
--- a/src/smtp_proxy.c
+++ b/src/smtp_proxy.c
@@ -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 */
};
diff --git a/src/worker.c b/src/worker.c
index 3939db702..a4ef7a81a 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -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, \