aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-12-03 18:13:28 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-12-03 18:13:28 +0300
commit56379fcf26379a1588e3ca9ad4bdb1c7f370d2c7 (patch)
treedb67e8033ab548b55dac4cf68d245dcee0752684
parent064948fca0ca6b579c4494c18223c1ea2d68208a (diff)
downloadrspamd-56379fcf26379a1588e3ca9ad4bdb1c7f370d2c7.tar.gz
rspamd-56379fcf26379a1588e3ca9ad4bdb1c7f370d2c7.zip
* Another fixes to synchronization of statfiles
-rw-r--r--src/buffer.c5
-rw-r--r--src/controller.c4
-rw-r--r--src/statfile_sync.c17
3 files changed, 14 insertions, 12 deletions
diff --git a/src/buffer.c b/src/buffer.c
index d55b88d4d..ac0c43e21 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -208,6 +208,9 @@ read_buffers (int fd, rspamd_io_dispatcher_t * d, gboolean skip_read)
return;
}
/* Move remaining string to begin of buffer (draining) */
+ /* Reinit pointers as buffer may be changed */
+ len = &d->in_buf->data->len;
+ pos = &d->in_buf->pos;
memmove (d->in_buf->data->begin, c + 1, *len - r - 1);
b = d->in_buf->data->begin;
c = b;
@@ -236,6 +239,8 @@ read_buffers (int fd, rspamd_io_dispatcher_t * d, gboolean skip_read)
return;
}
/* Move remaining string to begin of buffer (draining) */
+ len = &d->in_buf->data->len;
+ pos = &d->in_buf->pos;
memmove (d->in_buf->data->begin, c, *len - r);
b = d->in_buf->data->begin;
c = b;
diff --git a/src/controller.c b/src/controller.c
index caa538823..6df3a220c 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -295,10 +295,6 @@ process_sync_command (struct controller_session *session, char **args)
return FALSE;
}
- if (rev == 0) {
- return write_whole_statfile (session, symbol, ccf);
- }
-
while (binlog_sync (binlog, rev, &time, &data)) {
r = snprintf (out_buf, sizeof (out_buf), "%lu %lu %lu" CRLF, (long unsigned)rev, (long unsigned)time, (long unsigned)data->len);
rspamd_dispatcher_write (session->dispatcher, out_buf, r, TRUE, FALSE);
diff --git a/src/statfile_sync.c b/src/statfile_sync.c
index 5d2e9283d..490deb0fd 100644
--- a/src/statfile_sync.c
+++ b/src/statfile_sync.c
@@ -87,7 +87,7 @@ static gboolean
parse_revision_line (struct rspamd_sync_ctx *ctx, f_str_t *in)
{
int i, state = 0;
- char *p, *c, t;
+ char *p, *c, numbuf[sizeof("18446744073709551615")];
uint64_t *val;
/* First of all try to find END line */
@@ -104,18 +104,19 @@ parse_revision_line (struct rspamd_sync_ctx *ctx, f_str_t *in)
return TRUE;
}
- msg_info ("got string: %V", in);
/* Now try to extract 3 numbers from string: revision, time and length */
p = in->begin;
val = &ctx->new_rev;
for (i = 0; i < in->len; i ++, p ++) {
if (g_ascii_isspace (*p) || i == in->len - 1) {
if (state == 1) {
- t = *p;
- *p = '\0';
+ if (i == in->len - 1) {
+ /* One more character */
+ p ++;
+ }
+ g_strlcpy (numbuf, c, MIN (p - c + 1, sizeof (numbuf)));
errno = 0;
- *val = strtoull (c, NULL, 10);
- *p = t;
+ *val = strtoull (numbuf, NULL, 10);
if (errno != 0) {
msg_info ("parse_revision_line: cannot parse number %s", strerror (errno));
return FALSE;
@@ -193,7 +194,7 @@ sync_read (f_str_t * in, void *arg)
}
else {
/* Quit this session */
- msg_info ("sync_read: no sync needed for: %s", ctx->st->symbol);
+ msg_info ("sync_read: sync ended for: %s", ctx->st->symbol);
close (ctx->sock);
rspamd_remove_dispatcher (ctx->dispatcher);
ctx->is_busy = FALSE;
@@ -212,8 +213,8 @@ sync_read (f_str_t * in, void *arg)
}
statfile_set_revision (ctx->real_statfile, ctx->new_rev, ctx->new_time);
/* Now try to read other revision or END line */
- rspamd_set_dispatcher_policy (ctx->dispatcher, BUFFER_LINE, 0);
ctx->state = SYNC_STATE_READ_LINE;
+ rspamd_set_dispatcher_policy (ctx->dispatcher, BUFFER_LINE, 0);
break;
case SYNC_STATE_QUIT:
close (ctx->sock);