Browse Source

fixed unused var warning in imap_open()

locking cleanups from Oswald Buddenhagen <ossi@kde.org>
	* don't need to stat the lockfile since it will always be size 0
	* only remove lockfile when we actually succeeded in locking
Michael Elkins 23 years ago
parent
commit
54d8140f6e
3 changed files with 14 additions and 12 deletions
  1. 4 0
      AUTHORS
  2. 2 0
      imap.c
  3. 8 12
      maildir.c

+ 4 - 0
AUTHORS

@@ -1 +1,5 @@
 Michael Elkins <me@mutt.org>
+	* Author, Lead Developer
+
+Contributors:
+	Oswald Buddenhagen <ossi@kde.org>

+ 2 - 0
imap.c

@@ -567,6 +567,8 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap, int flags)
   int use_ssl = 0;
 #endif
 
+  (void) flags;
+
   if (imap)
   {
     /* determine whether or not we can reuse the existing session */

+ 8 - 12
maildir.c

@@ -34,24 +34,16 @@ static int
 do_lock (int fd, int flag)
 {
     struct flock lck;
-    struct stat sb;
-
-    if (fstat (fd, &sb))
-    {
-	perror ("fstat");
-	return -1;
-    }
 
     memset (&lck, 0, sizeof (lck));
     lck.l_type = flag;
     lck.l_whence = SEEK_SET;
     lck.l_start = 0;
-    lck.l_len = sb.st_size;
+    lck.l_len = 0;
 
     if (fcntl (fd, F_SETLK, &lck))
     {
 	perror ("fcntl");
-	close (fd);
 	return -1;
     }
 
@@ -141,6 +133,7 @@ maildir_lock (mailbox_t * m)
     if (do_lock (m->lockfd, F_WRLCK))
     {
 	close (m->lockfd);
+	m->lockfd = -1;
 	return -1;
     }
     return 0;
@@ -149,12 +142,16 @@ maildir_lock (mailbox_t * m)
 static void
 maildir_unlock (mailbox_t * m)
 {
-    char path[_POSIX_PATH_MAX];
+  char path[_POSIX_PATH_MAX];
 
+  if (m->lockfd != -1)
+  {
     snprintf (path, sizeof (path), "%s/isynclock", m->path);
     unlink (path);
     do_lock (m->lockfd, F_UNLCK);
     close (m->lockfd);
+    m->lockfd = -1;
+  }
 }
 
 /* open a maildir mailbox.
@@ -314,8 +311,7 @@ maildir_open (const char *path, int flags)
   err:
     if (m->db)
 	dbm_close (m->db);
-    if (m->lockfd != -1)
-	maildir_unlock (m);
+    maildir_unlock (m);
     free (m->path);
     free (m);
     return NULL;