Browse Source

[Feature] Rework system of workers' flags

pull/583/head
Vsevolod Stakhov 10 years ago
parent
commit
c442adeaa2
  1. 5
      src/controller.c
  2. 15
      src/fuzzy_storage.c
  3. 5
      src/hs_helper.c
  4. 5
      src/http_proxy.c
  5. 5
      src/lua_worker.c
  6. 8
      src/rspamd.c
  7. 15
      src/rspamd.h
  8. 5
      src/smtp_proxy.c
  9. 15
      src/worker.c

5
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 */
};

15
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 */

5
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 */
};

5
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
};

5
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 */
};

8
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);
}

15
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;

5
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 */
};

15
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, \

Loading…
Cancel
Save