]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fixing crashes from last changes
authorTimo Sirainen <tss@iki.fi>
Sun, 4 Jul 2004 22:19:49 +0000 (01:19 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 4 Jul 2004 22:19:49 +0000 (01:19 +0300)
--HG--
branch : HEAD

src/lib-index/mail-index-sync-private.h
src/lib-index/mail-index-sync-update.c
src/lib-index/mail-index-view-sync.c
src/lib-index/mail-transaction-log.c

index 1814a53ab0d872b104609e1e75e5e36155f3e36d..caeb99c46dae6b2323e9796a6e3940697af31306 100644 (file)
@@ -22,6 +22,12 @@ struct mail_index_sync_ctx {
        unsigned int lock_id;
 
        unsigned int sync_appends:1;
+};
+
+struct mail_index_sync_map_ctx {
+       struct mail_index_view *view;
+
+       unsigned int update_cache:1;
        unsigned int cache_locked:1;
 };
 
index 0d16d5e3284828b0ca687f22426ff8752d44b9c0..7719c58babcd4a1f3c558ad525c63dd4212b57b3 100644 (file)
@@ -57,22 +57,25 @@ mail_index_header_update_lowwaters(struct mail_index_header *hdr,
                hdr->first_deleted_uid_lowwater = rec->uid;
 }
 
-static void mail_index_sync_cache_expunge(struct mail_index_sync_ctx *sync_ctx,
+static void mail_index_sync_cache_expunge(struct mail_index_sync_map_ctx *ctx,
                                          uoff_t cache_offset)
 {
-       if (!sync_ctx->cache_locked) {
-               if (mail_cache_lock(sync_ctx->view->index->cache) <= 0)
+       if (!ctx->update_cache)
+               return;
+
+       if (!ctx->cache_locked) {
+               if (mail_cache_lock(ctx->view->index->cache) <= 0)
                        return;
-               sync_ctx->cache_locked = TRUE;
+               ctx->cache_locked = TRUE;
        }
 
-       (void)mail_cache_delete(sync_ctx->index->cache, cache_offset);
+       (void)mail_cache_delete(ctx->view->index->cache, cache_offset);
 }
 
 static int sync_expunge(const struct mail_transaction_expunge *e, void *context)
 {
-        struct mail_index_sync_ctx *sync_ctx = context;
-       struct mail_index_view *view = sync_ctx->view;
+        struct mail_index_sync_map_ctx *ctx = context;
+       struct mail_index_view *view = ctx->view;
        struct mail_index_map *map = view->map;
        struct mail_index_header *hdr = &map->hdr_copy;
        struct mail_index_record *rec;
@@ -91,10 +94,8 @@ static int sync_expunge(const struct mail_transaction_expunge *e, void *context)
                 rec = MAIL_INDEX_MAP_IDX(map, seq-1);
                mail_index_header_update_counts(hdr, rec->flags, 0);
                
-               if (rec->cache_offset != 0) {
-                       mail_index_sync_cache_expunge(sync_ctx,
-                                                     rec->cache_offset);
-               }
+               if (rec->cache_offset != 0)
+                       mail_index_sync_cache_expunge(ctx, rec->cache_offset);
        }
 
        /* @UNSAFE */
@@ -117,8 +118,8 @@ static int sync_expunge(const struct mail_transaction_expunge *e, void *context)
 static int sync_append(const struct mail_transaction_append_header *hdr,
                       const struct mail_index_record *rec, void *context)
 {
-        struct mail_index_sync_ctx *sync_ctx = context;
-       struct mail_index_view *view = sync_ctx->view;
+        struct mail_index_sync_map_ctx *ctx = context;
+       struct mail_index_view *view = ctx->view;
        struct mail_index_map *map = view->map;
        void *dest;
 
@@ -159,8 +160,8 @@ static int sync_append(const struct mail_transaction_append_header *hdr,
 static int sync_flag_update(const struct mail_transaction_flag_update *u,
                            void *context)
 {
-        struct mail_index_sync_ctx *sync_ctx = context;
-       struct mail_index_view *view = sync_ctx->view;
+        struct mail_index_sync_map_ctx *ctx = context;
+       struct mail_index_view *view = ctx->view;
        struct mail_index_record *rec;
        struct mail_index_header *hdr;
        uint8_t flag_mask, old_flags;
@@ -209,8 +210,8 @@ static int sync_flag_update(const struct mail_transaction_flag_update *u,
 static int sync_cache_reset(const struct mail_transaction_cache_reset *u,
                            void *context)
 {
-        struct mail_index_sync_ctx *sync_ctx = context;
-       struct mail_index_view *view = sync_ctx->view;
+        struct mail_index_sync_map_ctx *ctx = context;
+       struct mail_index_view *view = ctx->view;
        uint32_t i;
 
        view->map->hdr_copy.cache_file_seq = u->new_file_seq;
@@ -223,8 +224,8 @@ static int sync_cache_reset(const struct mail_transaction_cache_reset *u,
 static int sync_cache_update(const struct mail_transaction_cache_update *u,
                             void *context)
 {
-        struct mail_index_sync_ctx *sync_ctx = context;
-       struct mail_index_view *view = sync_ctx->view;
+        struct mail_index_sync_map_ctx *ctx = context;
+       struct mail_index_view *view = ctx->view;
        struct mail_index_record *rec;
        uint32_t seq;
        int ret;
@@ -239,12 +240,12 @@ static int sync_cache_update(const struct mail_transaction_cache_update *u,
        }
 
        rec = MAIL_INDEX_MAP_IDX(view->map, seq-1);
-       if (rec->cache_offset != 0) {
+       if (rec->cache_offset != 0 && ctx->update_cache) {
                /* we'll need to link the old and new cache records */
-               if (!sync_ctx->cache_locked) {
+               if (!ctx->cache_locked) {
                        if (mail_cache_lock(view->index->cache) <= 0)
                                return -1;
-                       sync_ctx->cache_locked = TRUE;
+                       ctx->cache_locked = TRUE;
                }
 
                if (mail_cache_link(view->index->cache,
@@ -258,10 +259,10 @@ static int sync_cache_update(const struct mail_transaction_cache_update *u,
 static int sync_header_update(const struct mail_transaction_header_update *u,
                              void *context)
 {
-        struct mail_index_sync_ctx *sync_ctx = context;
+        struct mail_index_sync_map_ctx *ctx = context;
        void *data;
 
-       data = PTR_OFFSET(&sync_ctx->view->map->hdr_copy, u->offset);
+       data = PTR_OFFSET(&ctx->view->map->hdr_copy, u->offset);
        memcpy(data, u->data, u->size);
        return 1;
 }
@@ -271,8 +272,8 @@ sync_extra_rec_update(const struct mail_transaction_extra_rec_header *hdr,
                      const struct mail_transaction_extra_rec_update *u,
                      void *context)
 {
-        struct mail_index_sync_ctx *sync_ctx = context;
-       struct mail_index_view *view = sync_ctx->view;
+        struct mail_index_sync_map_ctx *ctx = context;
+       struct mail_index_view *view = ctx->view;
        struct mail_index_record *rec;
        uint32_t seq;
        uint16_t offset, size;
@@ -392,6 +393,7 @@ int mail_index_sync_update_index(struct mail_index_sync_ctx *sync_ctx)
        struct mail_index *index = sync_ctx->index;
        struct mail_index_view *view = sync_ctx->view;
        struct mail_index_map *map;
+        struct mail_index_sync_map_ctx sync_map_ctx;
        const struct mail_transaction_header *hdr;
        const void *data;
        unsigned int count, old_lock_id;
@@ -399,6 +401,10 @@ int mail_index_sync_update_index(struct mail_index_sync_ctx *sync_ctx)
        uoff_t offset;
        int ret, had_dirty, skipped;
 
+       memset(&sync_map_ctx, 0, sizeof(sync_map_ctx));
+       sync_map_ctx.view = view;
+        sync_map_ctx.update_cache = TRUE;
+
        /* we'll have to update view->lock_id to avoid mail_index_view_lock()
           trying to update the file later. */
        old_lock_id = view->lock_id;
@@ -463,15 +469,15 @@ int mail_index_sync_update_index(struct mail_index_sync_ctx *sync_ctx)
 
                if (mail_transaction_map(index, hdr, data,
                                         &mail_index_map_sync_funcs,
-                                        sync_ctx) < 0) {
+                                        &sync_map_ctx) < 0) {
                        ret = -1;
                        break;
                }
        }
 
-       if (sync_ctx->cache_locked) {
+       if (sync_map_ctx.cache_locked) {
                mail_cache_unlock(index->cache);
-               sync_ctx->cache_locked = FALSE;
+               sync_map_ctx.cache_locked = FALSE;
        }
 
        if (ret < 0) {
index cc9a764d8dc86e72b4ec5f3fafb3a4b336cd19f5..6bdc90fa3a583d1f390d24ba3dd73f253481c7a5 100644 (file)
@@ -190,8 +190,14 @@ static int mail_index_view_sync_next_trans(struct mail_index_view_sync_ctx *ctx,
           see only updated information. */
        if (ctx->sync_map_update &&
            (ctx->hdr->type & MAIL_TRANSACTION_EXPUNGE) == 0) {
+               struct mail_index_sync_map_ctx sync_map_ctx;
+
+               memset(&sync_map_ctx, 0, sizeof(sync_map_ctx));
+               sync_map_ctx.view = view;
+
                if (mail_transaction_map(view->index, ctx->hdr, ctx->data,
-                                        &mail_index_map_sync_funcs, view) < 0)
+                                        &mail_index_map_sync_funcs,
+                                        &sync_map_ctx) < 0)
                        return -1;
        }
 
index 5f0e0f6e90a348eac8f873e2fe8670d3ae45f09e..82fcd699bd1b68792802f419425d848788660a4b 100644 (file)
@@ -970,7 +970,8 @@ static int mail_transaction_log_scan_pending(struct mail_transaction_log *log,
 
        /* make sure we're not writing cache_offsets to old cache file */
        if (t->new_cache_file_seq == 0 && max_cache_file_seq != 0 &&
-           max_cache_file_seq != t->last_cache_file_seq) {
+           max_cache_file_seq != t->last_cache_file_seq &&
+           t->cache_updates != NULL) {
                buffer_free(t->cache_updates);
                t->cache_updates = NULL;
        }
@@ -1103,8 +1104,10 @@ int mail_transaction_log_append(struct mail_index_transaction *t,
        }
 
        if (mail_index_lock_shared(log->index, TRUE, &lock_id) < 0) {
-               if (!log->index->log_locked)
-                       (void)mail_transaction_log_file_lock(file, F_UNLCK);
+               if (!log->index->log_locked) {
+                       (void)mail_transaction_log_file_lock(log->head,
+                                                            F_UNLCK);
+               }
                return -1;
        }
        idx_hdr = *log->index->hdr;