From 54d8140f6e0154c4af0c8c68e04e43b6d7e9c696 Mon Sep 17 00:00:00 2001 From: Michael Elkins Date: Wed, 19 Jun 2002 01:11:36 +0000 Subject: [PATCH] fixed unused var warning in imap_open() locking cleanups from Oswald Buddenhagen * don't need to stat the lockfile since it will always be size 0 * only remove lockfile when we actually succeeded in locking --- AUTHORS | 4 ++++ imap.c | 2 ++ maildir.c | 20 ++++++++------------ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/AUTHORS b/AUTHORS index 0735ac0..fb7d614 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1 +1,5 @@ Michael Elkins + * Author, Lead Developer + +Contributors: + Oswald Buddenhagen diff --git a/imap.c b/imap.c index a955ff3..a07710e 100644 --- a/imap.c +++ b/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 */ diff --git a/maildir.c b/maildir.c index 6528c3e..799a3eb 100644 --- a/maildir.c +++ b/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;