aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-09-28 19:11:05 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-09-28 19:11:05 +0400
commitee3d2182e1ce2a65822ac5a7dc51201a7c8b327d (patch)
treef8d9de66f3d7bb77ce7e571bf210a40a91d67ea3 /src
parente1fea1e66d0f1111e934bb0e86bd2ce25da6df6e (diff)
downloadrspamd-ee3d2182e1ce2a65822ac5a7dc51201a7c8b327d.tar.gz
rspamd-ee3d2182e1ce2a65822ac5a7dc51201a7c8b327d.zip
* Fix race between learn and classify
Diffstat (limited to 'src')
-rw-r--r--src/classifiers/winnow.c6
-rw-r--r--src/controller.c4
-rw-r--r--src/statfile.c6
-rw-r--r--src/statfile.h10
4 files changed, 17 insertions, 9 deletions
diff --git a/src/classifiers/winnow.c b/src/classifiers/winnow.c
index 6abd973ed..0b156176e 100644
--- a/src/classifiers/winnow.c
+++ b/src/classifiers/winnow.c
@@ -126,7 +126,11 @@ winnow_classify (struct classifier_ctx *ctx, statfile_pool_t *pool, GTree *input
}
}
- g_tree_foreach (input, classify_callback, &data);
+ if (data.file != NULL) {
+ statfile_pool_lock_file (pool, data.file);
+ g_tree_foreach (input, classify_callback, &data);
+ statfile_pool_unlock_file (pool, data.file);
+ }
if (data.count != 0) {
*res = (data.sum / data.count);
diff --git a/src/controller.c b/src/controller.c
index 82dc02c0f..c88994b9f 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -411,6 +411,9 @@ controller_read_socket (f_str_t *in, void *arg)
case STATE_COMMAND:
s = fstrcstr (in, session->session_pool);
params = g_strsplit (s, " ", -1);
+
+ memory_pool_add_destructor (session->session_pool, (pool_destruct_func)g_strfreev, params);
+
len = g_strv_length (params);
if (len > 0) {
cmd = g_strstrip (params[0]);
@@ -446,7 +449,6 @@ controller_read_socket (f_str_t *in, void *arg)
}
}
- g_strfreev (params);
break;
case STATE_LEARN:
session->learn_buf = in;
diff --git a/src/statfile.c b/src/statfile.c
index d1382e368..20b415bf6 100644
--- a/src/statfile.c
+++ b/src/statfile.c
@@ -171,8 +171,7 @@ statfile_pool_open (statfile_pool_t *pool, char *filename)
}
- /* XXX: this is temporary copy of name to avoid strdup early */
- new_file->filename = filename;
+ g_strlcpy (new_file->filename, filename, sizeof (new_file->filename));
new_file->len = st.st_size;
if (statfile_pool_check (new_file) == -1) {
pool->opened --;
@@ -180,7 +179,6 @@ statfile_pool_open (statfile_pool_t *pool, char *filename)
}
pool->occupied += st.st_size;
- new_file->filename = memory_pool_strdup (pool->pool, filename);
new_file->open_time = time (NULL);
new_file->access_time = new_file->open_time;
new_file->lock = memory_pool_get_mutex (pool->pool);
@@ -400,7 +398,7 @@ stat_file_t *
statfile_pool_is_open (statfile_pool_t *pool, char *filename)
{
static stat_file_t f, *ret;
- f.filename = filename;
+ g_strlcpy (f.filename, filename, sizeof (f.filename));
ret = bsearch (&f, pool->files, pool->opened, sizeof (stat_file_t), cmpstatfile);
return ret;
}
diff --git a/src/statfile.h b/src/statfile.h
index be5d15b71..de2ced1b0 100644
--- a/src/statfile.h
+++ b/src/statfile.h
@@ -32,7 +32,7 @@ struct stat_file_header {
* Section header
*/
struct stat_file_section {
- uint32_t code; /**< section's code */
+ uint64_t code; /**< section's code */
uint64_t length; /**< section's length in blocks */
};
@@ -42,8 +42,8 @@ struct stat_file_section {
struct stat_file_block {
uint32_t hash1; /**< hash1 (also acts as index) */
uint32_t hash2; /**< hash2 */
- float value; /**< float value */
uint32_t last_access; /**< last access to block since create time of file */
+ float value; /**< float value */
};
/**
@@ -59,7 +59,11 @@ struct stat_file {
* Common view of statfile object
*/
typedef struct stat_file_s {
- char *filename; /**< name of file */
+#ifdef HAVE_PATH_MAX
+ char filename[PATH_MAX]; /**< name of file */
+#else
+ char filename[MAXPATHLEN]; /**< name of file */
+#endif
int fd; /**< descriptor */
void *map; /**< mmaped area */
off_t seek_pos; /**< current seek position */