return FALSE;
}
+gboolean
+rspamd_worker_check_controller_presence (struct rspamd_worker *w)
+{
+ if (w->index == 0) {
+ GQuark our_type = w->type;
+ gboolean controller_seen = FALSE;
+ GList *cur;
+
+ enum {
+ low_priority_worker,
+ high_priority_worker
+ } our_priority;
+
+ if (our_type == g_quark_from_static_string("rspamd_proxy")) {
+ our_priority = low_priority_worker;
+ }
+ else if (our_type == g_quark_from_static_string("normal")) {
+ our_priority = high_priority_worker;
+ }
+ else {
+ msg_err ("function is called for a wrong worker type: %s", g_quark_to_string(our_type));
+ return FALSE;
+ }
+
+ cur = w->srv->cfg->workers;
+
+ while (cur) {
+ struct rspamd_worker_conf *cf;
+
+ cf = (struct rspamd_worker_conf *)cur->data;
+
+ if (our_priority == low_priority_worker) {
+ if ((cf->type == g_quark_from_static_string("controller")) ||
+ (cf->type == g_quark_from_static_string("normal"))) {
+
+ if (cf->enabled && cf->count >= 0) {
+ controller_seen = TRUE;
+ break;
+ }
+ }
+ }
+ else {
+ if (cf->type == g_quark_from_static_string("controller")) {
+ if (cf->enabled && cf->count >= 0) {
+ controller_seen = TRUE;
+ break;
+ }
+ }
+ }
+
+ cur = g_list_next (cur);
+ }
+
+ if (!controller_seen) {
+ msg_info ("no controller or normal workers defined, execute "
+ "controller periodics in this worker");
+ w->flags |= RSPAMD_WORKER_CONTROLLER;
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
struct rspamd_worker_session_elt {
void *ptr;
guint *pref;
*/
gboolean rspamd_worker_is_primary_controller (struct rspamd_worker *w);
+/**
+ * Returns TRUE if a specific worker should take a role of a controller
+ */
+gboolean rspamd_worker_check_controller_presence (struct rspamd_worker *w);
+
/**
* Creates new session cache
* @param w
/* Additional initialisation needed */
rspamd_worker_init_scanner (worker, ctx->event_loop, ctx->resolver,
&ctx->lang_det);
- /* Always yse cfg->task_timeout */
ctx->task_timeout = rspamd_worker_check_and_adjust_timeout(ctx->cfg, NAN);
- if (worker->index == 0) {
- /*
- * If there are no controllers and no normal workers,
- * then pretend that we are a controller
- */
- gboolean controller_seen = FALSE;
- GList *cur;
-
- cur = worker->srv->cfg->workers;
-
- while (cur) {
- struct rspamd_worker_conf *cf;
-
- cf = (struct rspamd_worker_conf *)cur->data;
- if ((cf->type == g_quark_from_static_string ("controller")) ||
- (cf->type == g_quark_from_static_string ("normal"))) {
-
- if (cf->enabled && cf->count >= 0) {
- controller_seen = TRUE;
- break;
- }
- }
-
- cur = g_list_next (cur);
- }
-
- if (!controller_seen) {
- msg_info ("no controller or normal workers defined, execute "
- "controller periodics in this worker");
- worker->flags |= RSPAMD_WORKER_CONTROLLER;
- is_controller = TRUE;
- }
- }
+ is_controller = rspamd_worker_check_controller_presence (worker);
}
else {
worker->flags &= ~RSPAMD_WORKER_SCANNER;
rspamd_worker_init_scanner (worker, ctx->event_loop, ctx->resolver,
&ctx->lang_det);
- if (worker->index == 0) {
- /* If there are no controllers, then pretend that we are a controller */
- gboolean controller_seen = FALSE;
- GList *cur;
-
- cur = worker->srv->cfg->workers;
-
- while (cur) {
- struct rspamd_worker_conf *cf;
-
- cf = (struct rspamd_worker_conf *)cur->data;
- if (cf->type == g_quark_from_static_string ("controller")) {
- if (cf->enabled && cf->count >= 0) {
- controller_seen = TRUE;
- break;
- }
- }
-
- cur = g_list_next (cur);
- }
-
- if (!controller_seen) {
- msg_info_ctx ("no controller workers defined, execute "
- "controller periodics in this worker");
- worker->flags |= RSPAMD_WORKER_CONTROLLER;
- is_controller = TRUE;
- }
- }
+ is_controller = rspamd_worker_check_controller_presence (worker);
if (is_controller) {
rspamd_worker_init_controller (worker, NULL);