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
This commit is contained in:
parent
418b5e9a7a
commit
54d8140f6e
4
AUTHORS
4
AUTHORS
|
@ -1 +1,5 @@
|
||||||
Michael Elkins <me@mutt.org>
|
Michael Elkins <me@mutt.org>
|
||||||
|
* Author, Lead Developer
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Oswald Buddenhagen <ossi@kde.org>
|
||||||
|
|
2
imap.c
2
imap.c
|
@ -567,6 +567,8 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap, int flags)
|
||||||
int use_ssl = 0;
|
int use_ssl = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
(void) flags;
|
||||||
|
|
||||||
if (imap)
|
if (imap)
|
||||||
{
|
{
|
||||||
/* determine whether or not we can reuse the existing session */
|
/* determine whether or not we can reuse the existing session */
|
||||||
|
|
20
maildir.c
20
maildir.c
|
@ -34,24 +34,16 @@ static int
|
||||||
do_lock (int fd, int flag)
|
do_lock (int fd, int flag)
|
||||||
{
|
{
|
||||||
struct flock lck;
|
struct flock lck;
|
||||||
struct stat sb;
|
|
||||||
|
|
||||||
if (fstat (fd, &sb))
|
|
||||||
{
|
|
||||||
perror ("fstat");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset (&lck, 0, sizeof (lck));
|
memset (&lck, 0, sizeof (lck));
|
||||||
lck.l_type = flag;
|
lck.l_type = flag;
|
||||||
lck.l_whence = SEEK_SET;
|
lck.l_whence = SEEK_SET;
|
||||||
lck.l_start = 0;
|
lck.l_start = 0;
|
||||||
lck.l_len = sb.st_size;
|
lck.l_len = 0;
|
||||||
|
|
||||||
if (fcntl (fd, F_SETLK, &lck))
|
if (fcntl (fd, F_SETLK, &lck))
|
||||||
{
|
{
|
||||||
perror ("fcntl");
|
perror ("fcntl");
|
||||||
close (fd);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,6 +133,7 @@ maildir_lock (mailbox_t * m)
|
||||||
if (do_lock (m->lockfd, F_WRLCK))
|
if (do_lock (m->lockfd, F_WRLCK))
|
||||||
{
|
{
|
||||||
close (m->lockfd);
|
close (m->lockfd);
|
||||||
|
m->lockfd = -1;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -149,12 +142,16 @@ maildir_lock (mailbox_t * m)
|
||||||
static void
|
static void
|
||||||
maildir_unlock (mailbox_t * m)
|
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);
|
snprintf (path, sizeof (path), "%s/isynclock", m->path);
|
||||||
unlink (path);
|
unlink (path);
|
||||||
do_lock (m->lockfd, F_UNLCK);
|
do_lock (m->lockfd, F_UNLCK);
|
||||||
close (m->lockfd);
|
close (m->lockfd);
|
||||||
|
m->lockfd = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* open a maildir mailbox.
|
/* open a maildir mailbox.
|
||||||
|
@ -314,8 +311,7 @@ maildir_open (const char *path, int flags)
|
||||||
err:
|
err:
|
||||||
if (m->db)
|
if (m->db)
|
||||||
dbm_close (m->db);
|
dbm_close (m->db);
|
||||||
if (m->lockfd != -1)
|
maildir_unlock (m);
|
||||||
maildir_unlock (m);
|
|
||||||
free (m->path);
|
free (m->path);
|
||||||
free (m);
|
free (m);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user