]> source.dussan.org Git - rspamd.git/commitdiff
* Another fixes to synchronization of statfiles
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 3 Dec 2009 15:13:28 +0000 (18:13 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 3 Dec 2009 15:13:28 +0000 (18:13 +0300)
src/buffer.c
src/controller.c
src/statfile_sync.c

index d55b88d4d9bd4d150f9b13252de9172215de1414..ac0c43e214d57a8b701ace833eb0633f194dbe63 100644 (file)
@@ -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;
index caa538823c2219145d5702b0d90b3ff17a421ce0..6df3a220c38e0ee72d5c234ff37b53f42cac95bc 100644 (file)
@@ -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);
index 5d2e9283df83c72f55004fbafaa28e0dda253466..490deb0fd82db3cb2882fa122fb7388dd1ac3e61 100644 (file)
@@ -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);