From: Timo Sirainen Date: Thu, 15 May 2003 19:42:12 +0000 (+0300) Subject: Reset the header using mmaped memory + msync, instead of lseek() + write() X-Git-Tag: 1.1.alpha1~4634 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=291ce633d7065ba4ff0cf5ef9f1cecfdfca229c2;p=thirdparty%2Fdovecot%2Fcore.git Reset the header using mmaped memory + msync, instead of lseek() + write() which was buggy with OpenBSD (didn't update the mmap). --HG-- branch : HEAD --- diff --git a/src/lib-index/mail-index-data.c b/src/lib-index/mail-index-data.c index b25bb39abd..cb9a127439 100644 --- a/src/lib-index/mail-index-data.c +++ b/src/lib-index/mail-index-data.c @@ -358,21 +358,17 @@ int mail_index_data_reset(struct mail_index_data *data) memset(&hdr, 0, sizeof(struct mail_index_data_header)); hdr.indexid = data->index->indexid; hdr.used_file_size = sizeof(struct mail_index_data_header); + memcpy(data->mmap_base, &hdr, sizeof(hdr)); - if (data->anon_mmap) { - memcpy(data->mmap_base, &hdr, sizeof(hdr)); + if (data->anon_mmap) return TRUE; - } + + if (msync(data->mmap_base, sizeof(hdr), MS_SYNC) < 0) + return index_data_set_syscall_error(data, "msync()"); if (file_set_size(data->fd, INDEX_DATA_INITIAL_SIZE) < 0) return index_data_set_syscall_error(data, "file_set_size()"); - if (lseek(data->fd, 0, SEEK_SET) < 0) - return index_data_set_syscall_error(data, "lseek()"); - - if (write_full(data->fd, &hdr, sizeof(hdr)) < 0) - return index_data_set_syscall_error(data, "write_full()"); - data->modified = FALSE; data->fsynced = FALSE; return mmap_update(data, 0, 0);