summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2010-08-26 17:45:09 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2010-08-26 17:45:09 +0400
commite34968660861edbc6b180e93961310189ad3309e (patch)
tree785e987f95af16b0abe5697d885c45f88f3e059c /src
parent460852a9aba9aa7a5bfc9a83d243d9a45fe14f34 (diff)
downloadrspamd-e34968660861edbc6b180e93961310189ad3309e.tar.gz
rspamd-e34968660861edbc6b180e93961310189ad3309e.zip
* Fix races in fuzzy storage
Diffstat (limited to 'src')
-rw-r--r--src/classifiers/winnow.c4
-rw-r--r--src/fuzzy_storage.c36
2 files changed, 23 insertions, 17 deletions
diff --git a/src/classifiers/winnow.c b/src/classifiers/winnow.c
index c0c1bd755..f1f991486 100644
--- a/src/classifiers/winnow.c
+++ b/src/classifiers/winnow.c
@@ -382,7 +382,9 @@ winnow_learn (struct classifier_ctx *ctx, statfile_pool_t *pool, const char *sym
nodes = g_tree_nnodes (input) / FEATURE_WINDOW_SIZE;
if (nodes < minnodes) {
msg_info ("do not learn message as it has too few tokens: %d, while %d min", nodes, minnodes);
- *sum = 0;
+ if (sum != NULL) {
+ *sum = 0;
+ }
g_set_error (err,
winnow_error_quark(), /* error domain */
1, /* error code */
diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c
index df138b38a..cff5d45d8 100644
--- a/src/fuzzy_storage.c
+++ b/src/fuzzy_storage.c
@@ -101,14 +101,9 @@ sig_handler (int signo, siginfo_t *info, void *unused)
reopen_log ();
break;
case SIGINT:
- /* Ignore SIGINT as we should got SIGTERM after it anyway */
- return;
case SIGTERM:
-#ifdef WITH_PROFILER
- exit (0);
-#else
- _exit (1);
-#endif
+ /* Ignore SIGINT and SIGTERM as they are handled by libevent handler */
+ return;
break;
}
}
@@ -279,6 +274,7 @@ read_hashes_file (struct rspamd_worker *wrk)
int r, fd, i, version = 0;
struct stat st;
char *filename, header[4];
+ gboolean touch_stat = TRUE;
struct rspamd_fuzzy_node *node;
struct {
int32_t value;
@@ -288,6 +284,10 @@ read_hashes_file (struct rspamd_worker *wrk)
#ifdef WITH_JUDY
PPvoid_t pvalue;
+ if (server_stat->fuzzy_hashes != 0) {
+ touch_stat = FALSE;
+ }
+
if (use_judy) {
jtree = NULL;
}
@@ -370,7 +370,9 @@ read_hashes_file (struct rspamd_worker *wrk)
}
#endif
bloom_add (bf, node->h.hash_pipe);
- server_stat->fuzzy_hashes ++;
+ if (touch_stat) {
+ server_stat->fuzzy_hashes ++;
+ }
}
#ifdef WITH_JUDY
@@ -775,6 +777,15 @@ start_fuzzy_storage (struct rspamd_worker *worker)
#endif
}
+ /* Listen event */
+ while ((worker->cf->listen_sock = make_udp_socket (&worker->cf->bind_addr, worker->cf->bind_port, TRUE, TRUE)) == -1) {
+ sleep (1);
+ if (++retries > MAX_RETRIES) {
+ msg_err ("cannot bind to socket, exiting");
+ exit (0);
+ }
+ }
+
/* Init bloom filter */
bf = bloom_create (20000000L, DEFAULT_BLOOM_HASHES);
/* Try to read hashes from file */
@@ -788,14 +799,7 @@ start_fuzzy_storage (struct rspamd_worker *worker)
tmv.tv_usec = 0;
evtimer_add (&tev, &tmv);
- /* Accept event */
- while ((worker->cf->listen_sock = make_udp_socket (&worker->cf->bind_addr, worker->cf->bind_port, TRUE, TRUE)) == -1) {
- sleep (1);
- if (++retries > MAX_RETRIES) {
- msg_err ("cannot bind to socket, exiting");
- exit (0);
- }
- }
+
event_set (&worker->bind_ev, worker->cf->listen_sock, EV_READ | EV_PERSIST, accept_fuzzy_socket, (void *)worker);
event_add (&worker->bind_ev, NULL);