[dovecot-cvs] dovecot/src/lib file-dotlock.c,1.24,1.25

cras at dovecot.org cras at dovecot.org
Sat Mar 5 21:03:06 EET 2005


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv15846

Modified Files:
	file-dotlock.c 
Log Message:
If we failed to lock the dotlock, don't try to close the file twice.



Index: file-dotlock.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/file-dotlock.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- file-dotlock.c	31 Jan 2005 18:52:23 -0000	1.24
+++ file-dotlock.c	5 Mar 2005 19:03:03 -0000	1.25
@@ -270,6 +270,8 @@
 
 	if (lock_info->temp_path == NULL) {
 		/* we'll need our temp file first. */
+		i_assert(lock_info->fd == -1);
+
 		if (temp_prefix == NULL) {
 			temp_prefix = t_strconcat(".temp.", my_hostname, ".",
 						  my_pid, ".", NULL);
@@ -381,15 +383,9 @@
 		now = time(NULL);
 	} while (now < max_wait_time);
 
-	if (ret <= 0 && lock_info.fd != -1) {
-		int old_errno = errno;
-
-		if (close(lock_info.fd) < 0)
-			i_error("close(%s) failed: %m", path);
-		errno = old_errno;
-	} else {
+	if (ret > 0) {
 		if (fstat(lock_info.fd, &st) < 0) {
-			i_error("fstat(%s) failed: %m", path);
+			i_error("fstat(%s) failed: %m", lock_path);
 			ret = -1;
 		} else {
 			dotlock->dev = st.st_dev;
@@ -397,9 +393,18 @@
 
 			dotlock->path = i_strdup(path);
 			dotlock->fd = lock_info.fd;
+			lock_info.fd = -1;
 		}
 	}
 
+	if (lock_info.fd != -1) {
+		int old_errno = errno;
+
+		if (close(lock_info.fd) < 0)
+			i_error("close(%s) failed: %m", lock_path);
+		errno = old_errno;
+	}
+
 	if (ret == 0)
 		errno = EAGAIN;
 	return ret;



More information about the dovecot-cvs mailing list