Mercurial > dovecot > original-hg > dovecot-1.2
changeset 544:42e65c2ba49d HEAD
Added --enable-debug. Currently it just forces file locks so that index
files can't be written to when not holding exclusive lock. Also main index
file can't be even read if we're unlocked (other files don't get
notification of unlock, so they don't do this at least yet).
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 28 Oct 2002 11:31:40 +0200 |
parents | 52fd3d82e59a |
children | c97f631bd26d |
files | acconfig.h configure.in src/lib-index/mail-index-data.c src/lib-index/mail-index-util.h src/lib-index/mail-index.c src/lib-index/mail-modifylog.c src/lib-index/mail-tree.c |
diffstat | 7 files changed, 32 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/acconfig.h Mon Oct 28 11:00:25 2002 +0200 +++ b/acconfig.h Mon Oct 28 11:31:40 2002 +0200 @@ -1,3 +1,6 @@ +/* Build with extra debugging checks */ +#undef DEBUG + /* Build with SSL/TLS support */ #undef HAVE_SSL
--- a/configure.in Mon Oct 28 11:00:25 2002 +0200 +++ b/configure.in Mon Oct 28 11:31:40 2002 +0200 @@ -28,6 +28,12 @@ fi, want_ipv6=yes) +AC_ARG_ENABLE(debug, +[ --enable-debug Enable some extra checks for debugging], + if test x$enableval = xyes; then + AC_DEFINE(DEBUG) + fi) + AC_ARG_WITH(file-offset-size, [ --with-file-offset-size=BITS Set size of file offsets. Usually 32 or 64. (default: 64 if available)],
--- a/src/lib-index/mail-index-data.c Mon Oct 28 11:00:25 2002 +0200 +++ b/src/lib-index/mail-index-data.c Mon Oct 28 11:31:40 2002 +0200 @@ -189,6 +189,7 @@ data->mmap_used_length = hdr->used_file_size; data->header = hdr; + debug_mprotect(data->mmap_base, data->mmap_full_length, data->index); return TRUE; }
--- a/src/lib-index/mail-index-util.h Mon Oct 28 11:00:25 2002 +0200 +++ b/src/lib-index/mail-index-util.h Mon Oct 28 11:31:40 2002 +0200 @@ -1,6 +1,20 @@ #ifndef __MAIL_INDEX_UTIL_H #define __MAIL_INDEX_UTIL_H +/* Get index's lock state as mprotect() argument */ +#define MAIL_INDEX_PROT(index) \ + ((index)->lock_type == MAIL_LOCK_EXCLUSIVE ? (PROT_READ|PROT_WRITE) : \ + (index)->lock_type == MAIL_LOCK_SHARED || !(index)->opened ? \ + PROT_READ : PROT_NONE) + +/* DEBUG: Force mmap() locks with mprotect() */ +#ifdef DEBUG +# define debug_mprotect(mmap_base, mmap_length, index) \ + mprotect(mmap_base, mmap_length, MAIL_INDEX_PROT(index)) +#else +# define debug_mprotect(mmap_base, mmap_length, index) +#endif + /* Set the current error message */ int index_set_error(MailIndex *index, const char *fmt, ...) __attr_format__(2, 3);
--- a/src/lib-index/mail-index.c Mon Oct 28 11:00:25 2002 +0200 +++ b/src/lib-index/mail-index.c Mon Oct 28 11:31:40 2002 +0200 @@ -313,6 +313,7 @@ return mail_index_write_header_changes(index); } + debug_mprotect(index->mmap_base, index->mmap_full_length, index); return TRUE; } @@ -331,7 +332,9 @@ if (file_wait_lock(index->fd, MAIL_LOCK_TO_FLOCK(lock_type), DEFAULT_LOCK_TIMEOUT) <= 0) return index_set_syscall_error(index, "file_wait_lock()"); + index->lock_type = lock_type; + debug_mprotect(index->mmap_base, index->mmap_full_length, index); if (!mail_index_mmap_update(index)) { (void)mail_index_set_lock(index, MAIL_LOCK_UNLOCK);
--- a/src/lib-index/mail-modifylog.c Mon Oct 28 11:00:25 2002 +0200 +++ b/src/lib-index/mail-modifylog.c Mon Oct 28 11:31:40 2002 +0200 @@ -168,6 +168,8 @@ if (!forced && file->header != NULL && file->mmap_full_length >= file->header->used_file_size) { file->mmap_used_length = file->header->used_file_size; + debug_mprotect(file->mmap_base, file->mmap_full_length, + file->log->index); return TRUE; } @@ -235,6 +237,8 @@ file->header = file->mmap_base; file->mmap_used_length = hdr->used_file_size; + debug_mprotect(file->mmap_base, file->mmap_full_length, + file->log->index); return TRUE; }