From: Vsevolod Stakhov Date: Thu, 3 Dec 2009 15:13:28 +0000 (+0300) Subject: * Another fixes to synchronization of statfiles X-Git-Tag: 0.3.0~117 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=56379fcf26379a1588e3ca9ad4bdb1c7f370d2c7;p=rspamd.git * Another fixes to synchronization of statfiles --- 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);