From 860feef97ed04b130d247043e1945414aa280cea Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 5 May 2009 16:57:11 +0400 Subject: [PATCH] * Enable counters interface * Move modules configuration to init stage --- src/main.c | 10 ++++++++-- src/plugins/regexp.c | 1 + src/util.c | 4 +--- src/worker.c | 6 ------ 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main.c b/src/main.c index 668c0d7cc..d64884924 100644 --- a/src/main.c +++ b/src/main.c @@ -465,6 +465,8 @@ main (int argc, char **argv, char **env) } fclose (f); + /* Init counters */ + counters = rspamd_hash_new_shared (rspamd->server_pool, g_str_hash, g_str_equal, 64); /* Init C modules */ for (i = 0; i < MODULES_NUM; i ++) { @@ -491,6 +493,7 @@ main (int argc, char **argv, char **env) return res ? EXIT_SUCCESS : EXIT_FAILURE; } + /* Create listen socket */ listen_sock = create_listen_socket (&rspamd->cfg->bind_addr, rspamd->cfg->bind_port, rspamd->cfg->bind_family, rspamd->cfg->bind_host); @@ -574,8 +577,11 @@ main (int argc, char **argv, char **env) /* Init statfile pool */ rspamd->statfile_pool = statfile_pool_new (cfg->max_statfile_size); - /* Init counters */ - counters = rspamd_hash_new_shared (rspamd->server_pool, g_str_hash, g_str_equal, 64); + + /* Perform modules configuring */ + for (i = 0; i < MODULES_NUM; i ++) { + modules[i].module_config_func (cfg); + } for (i = 0; i < cfg->workers_number; i++) { fork_worker (rspamd, listen_sock, TYPE_WORKER); diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 4eaca581e..8efc013dc 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -185,6 +185,7 @@ regexp_module_config (struct config_file *cfg) if (!read_regexp_expression (regexp_module_ctx->regexp_pool, cur_item, cur->param, cur->value, cfg)) { res = FALSE; } + set_counter (cur_item->symbol, 0); regexp_module_ctx->items = g_list_prepend (regexp_module_ctx->items, cur_item); } } diff --git a/src/util.c b/src/util.c index 93774a9ae..eb57d6c88 100644 --- a/src/util.c +++ b/src/util.c @@ -819,13 +819,12 @@ set_counter (const char *name, long int value) double alpha; char *key; -#if 0 cd = rspamd_hash_lookup (counters, (gpointer)name); if (cd == NULL) { cd = memory_pool_alloc_shared (counters->pool, sizeof (struct counter_data)); cd->value = value; - cd->number = 1; + cd->number = 0; key = memory_pool_strdup_shared (counters->pool, name); rspamd_hash_insert (counters, (gpointer)key, (gpointer)cd); } @@ -838,7 +837,6 @@ set_counter (const char *name, long int value) memory_pool_wunlock_rwlock (counters->lock); } -#endif } /* diff --git a/src/worker.c b/src/worker.c index e97454121..263d1eb93 100644 --- a/src/worker.c +++ b/src/worker.c @@ -309,7 +309,6 @@ void start_worker (struct rspamd_worker *worker, int listen_sock) { struct sigaction signals; - int i; #ifdef WITH_PROFILER extern void _start (void), etext (void); @@ -356,11 +355,6 @@ start_worker (struct rspamd_worker *worker, int listen_sock) event_set(&worker->bind_ev, listen_sock, EV_READ | EV_PERSIST, accept_socket, (void *)worker); event_add(&worker->bind_ev, NULL); - /* Perform modules configuring */ - for (i = 0; i < MODULES_NUM; i ++) { - modules[i].module_config_func (worker->srv->cfg); - } - /* Send SIGUSR2 to parent */ kill (getppid (), SIGUSR2); -- 2.39.5