aboutsummaryrefslogtreecommitdiffstats
path: root/src/fuzzy_storage.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-10-30 18:30:51 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-10-30 18:30:51 +0300
commitbb1b1f7889abe5c98a7628ba82e07b70a2142658 (patch)
treead51257652a78e63bc030d517ba6a55241a69e3f /src/fuzzy_storage.c
parent1290cafef2180e5435cbbfd5a72527d0be2f4970 (diff)
downloadrspamd-bb1b1f7889abe5c98a7628ba82e07b70a2142658.tar.gz
rspamd-bb1b1f7889abe5c98a7628ba82e07b70a2142658.zip
* Implement new system of managing rspamd processes
Diffstat (limited to 'src/fuzzy_storage.c')
-rw-r--r--src/fuzzy_storage.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c
index 702c5b7c5..68da96b44 100644
--- a/src/fuzzy_storage.c
+++ b/src/fuzzy_storage.c
@@ -109,12 +109,21 @@ sync_cache (struct rspamd_worker *wrk)
else {
expire = DEFAULT_EXPIRE;
}
+
+ /* Sync section */
+ if ((fd = open (filename, O_WRONLY)) != -1) {
+ /* Aqquire a lock */
+ (void)lock_file (fd, FALSE);
+ (void)unlock_file (fd, FALSE);
+ }
if ((fd = open (filename, O_WRONLY | O_TRUNC | O_CREAT, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH)) == -1) {
msg_err ("sync_cache: cannot create hash file %s: %s", filename, strerror (errno));
return;
}
+ (void)lock_file (fd, FALSE);
+
now = (uint64_t) time (NULL);
for (i = 0; i < BUCKETS; i++) {
cur = hashes[i]->head;
@@ -136,6 +145,7 @@ sync_cache (struct rspamd_worker *wrk)
}
}
+ (void)unlock_file (fd, FALSE);
close (fd);
}
@@ -196,6 +206,8 @@ read_hashes_file (struct rspamd_worker *wrk)
return FALSE;
}
+ (void)lock_file (fd, FALSE);
+
fstat (fd, &st);
for (;;) {
@@ -208,6 +220,9 @@ read_hashes_file (struct rspamd_worker *wrk)
bloom_add (bf, node->h.hash_pipe);
}
+ (void)unlock_file (fd, FALSE);
+ close (fd);
+
if (r > 0) {
msg_warn ("read_hashes_file: ignore garbadge at the end of file, length of garbadge: %d", r);
}
@@ -415,9 +430,6 @@ start_fuzzy_storage (struct rspamd_worker *worker)
signal_set (&sev, SIGTERM, sigterm_handler, (void *)worker);
signal_add (&sev, NULL);
- /* Send SIGUSR2 to parent */
- kill (getppid (), SIGUSR2);
-
/* Init bloom filter */
bf = bloom_create (20000000L, DEFAULT_BLOOM_HASHES);
/* Try to read hashes from file */