[dovecot-cvs] dovecot/src/lib-index mail-index-data.c,1.27,1.28 mail-index-util.h,1.6,1.7 mail-index.c,1.64,1.65 mail-modifylog.c,1.32,1.33 mail-tree.c,1.7,1.8

cras at procontrol.fi cras at procontrol.fi
Mon Oct 28 11:31:42 EET 2002


Update of /home/cvs/dovecot/src/lib-index
In directory danu:/tmp/cvs-serv13128/src/lib-index

Modified Files:
	mail-index-data.c mail-index-util.h mail-index.c 
	mail-modifylog.c mail-tree.c 
Log Message:
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).



Index: mail-index-data.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-data.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- mail-index-data.c	27 Oct 2002 06:37:18 -0000	1.27
+++ mail-index-data.c	28 Oct 2002 09:31:40 -0000	1.28
@@ -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;
 }
 

Index: mail-index-util.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-util.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- mail-index-util.h	27 Oct 2002 06:37:18 -0000	1.6
+++ mail-index-util.h	28 Oct 2002 09:31:40 -0000	1.7
@@ -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);

Index: mail-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- mail-index.c	27 Oct 2002 06:37:18 -0000	1.64
+++ mail-index.c	28 Oct 2002 09:31:40 -0000	1.65
@@ -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);

Index: mail-modifylog.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-modifylog.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- mail-modifylog.c	23 Oct 2002 20:41:35 -0000	1.32
+++ mail-modifylog.c	28 Oct 2002 09:31:40 -0000	1.33
@@ -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;
 }
 

Index: mail-tree.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-tree.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mail-tree.c	25 Oct 2002 02:25:52 -0000	1.7
+++ mail-tree.c	28 Oct 2002 09:31:40 -0000	1.8
@@ -69,6 +69,7 @@
 		return tree_set_syscall_error(tree, "mmap()");
 	}
 
+	debug_mprotect(tree->mmap_base, tree->mmap_full_length, tree->index);
 	return TRUE;
 }
 




More information about the dovecot-cvs mailing list