Commit accf1d99 accf1d99e04d805b959df61c72ac62fb0b039059 by Sergey Poznyakoff

Fix locking in pop3 and imap4d. This complements d0769b4f.

* lib/manlock.c (mailbox_open_and_lock): Open mailbox before retrieving
its locker, otherwise it is always NULL.
* pop3d/pop3d.c (main): Enforce mandatory locking.
1 parent 38ff0319
......@@ -110,6 +110,15 @@ mailbox_open_and_lock (mu_mailbox_t mbox, int flags)
mu_mailbox_get_url (mbox, &url);
urlstr = mu_url_to_string (url);
if ((status = mu_mailbox_open (mbox, flags)) != 0)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_open", urlstr, status);
return MU_ERR_FAILURE;
}
/* This is a mild race condition: mailbox needs to be opened in order to
obtain its locker. Other process can acquire the lock in the meantime,
but that's not critical, because manlock_lock below will fail if unable
to lock the mailbox anyway. */
status = mu_mailbox_get_locker (mbox, &lock);
if (status)
{
......@@ -145,11 +154,6 @@ mailbox_open_and_lock (mu_mailbox_t mbox, int flags)
mu_mailbox_set_locker (mbox, lock);
}
if ((status = mu_mailbox_open (mbox, flags)) != 0)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_open", urlstr, status);
return MU_ERR_FAILURE;
}
return manlock_lock (mbox);
}
......
......@@ -340,6 +340,7 @@ main (int argc, char **argv)
mu_alloc_die_hook = pop3d_alloc_die;
mu_log_syslog = 1;
manlock_mandatory_locking = 1;
if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param,
argc, argv, 0, NULL, server))
......