[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-lock.c, 1.11, 1.12

cras at dovecot.org cras at dovecot.org
Mon Dec 20 14:44:23 EET 2004


Update of /var/lib/cvs/dovecot/src/lib-storage/index/mbox
In directory talvi:/tmp/cvs-serv29205

Modified Files:
	mbox-lock.c 
Log Message:
Fix crashes when handling stale dotlocks.



Index: mbox-lock.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-lock.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- mbox-lock.c	8 Oct 2004 21:40:05 -0000	1.11
+++ mbox-lock.c	20 Dec 2004 12:44:19 -0000	1.12
@@ -186,21 +186,33 @@
 static int dotlock_callback(unsigned int secs_left, int stale, void *context)
 {
         struct mbox_lock_context *ctx = context;
-	int idx;
+	enum mbox_lock_type *lock_types;
+	int i;
 
 	if (stale && !ctx->dotlock_last_stale) {
-		/* get next index we wish to try locking */
-		for (idx = MBOX_LOCK_COUNT; idx > 0; idx--) {
-			if (ctx->lock_status[idx-1])
+		/* get next index we wish to try locking. it's the one after
+		   dotlocking. */
+		lock_types = ctx->lock_type == F_WRLCK ||
+			(ctx->lock_type == F_UNLCK &&
+			 ctx->ibox->mbox_lock_type == F_WRLCK) ?
+			write_locks : read_locks;
+
+		for (i = 0; lock_types[i] != (enum mbox_lock_type)-1; i++) {
+			if (lock_types[i] == MBOX_LOCK_DOTLOCK)
 				break;
 		}
 
-		if (mbox_lock_list(ctx, ctx->lock_type, 0, idx) <= 0) {
-			/* we couldn't get fcntl/flock - it's really locked */
-			ctx->dotlock_last_stale = TRUE;
-			return FALSE;
+		if (lock_types[i] != (enum mbox_lock_type)-1 &&
+		    lock_types[i+1] != (enum mbox_lock_type)-1) {
+			i++;
+			if (mbox_lock_list(ctx, ctx->lock_type, 0, i) <= 0) {
+				/* we couldn't get fd lock -
+				   it's really locked */
+				ctx->dotlock_last_stale = TRUE;
+				return FALSE;
+			}
+			(void)mbox_lock_list(ctx, F_UNLCK, 0, i);
 		}
-		(void)mbox_lock_list(ctx, F_UNLCK, 0, idx);
 	}
 	ctx->dotlock_last_stale = stale;
 



More information about the dovecot-cvs mailing list