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.
Showing
2 changed files
with
10 additions
and
5 deletions
... | @@ -110,6 +110,15 @@ mailbox_open_and_lock (mu_mailbox_t mbox, int flags) | ... | @@ -110,6 +110,15 @@ mailbox_open_and_lock (mu_mailbox_t mbox, int flags) |
110 | mu_mailbox_get_url (mbox, &url); | 110 | mu_mailbox_get_url (mbox, &url); |
111 | urlstr = mu_url_to_string (url); | 111 | urlstr = mu_url_to_string (url); |
112 | 112 | ||
113 | if ((status = mu_mailbox_open (mbox, flags)) != 0) | ||
114 | { | ||
115 | mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_open", urlstr, status); | ||
116 | return MU_ERR_FAILURE; | ||
117 | } | ||
118 | /* This is a mild race condition: mailbox needs to be opened in order to | ||
119 | obtain its locker. Other process can acquire the lock in the meantime, | ||
120 | but that's not critical, because manlock_lock below will fail if unable | ||
121 | to lock the mailbox anyway. */ | ||
113 | status = mu_mailbox_get_locker (mbox, &lock); | 122 | status = mu_mailbox_get_locker (mbox, &lock); |
114 | if (status) | 123 | if (status) |
115 | { | 124 | { |
... | @@ -145,11 +154,6 @@ mailbox_open_and_lock (mu_mailbox_t mbox, int flags) | ... | @@ -145,11 +154,6 @@ mailbox_open_and_lock (mu_mailbox_t mbox, int flags) |
145 | mu_mailbox_set_locker (mbox, lock); | 154 | mu_mailbox_set_locker (mbox, lock); |
146 | } | 155 | } |
147 | 156 | ||
148 | if ((status = mu_mailbox_open (mbox, flags)) != 0) | ||
149 | { | ||
150 | mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_open", urlstr, status); | ||
151 | return MU_ERR_FAILURE; | ||
152 | } | ||
153 | return manlock_lock (mbox); | 157 | return manlock_lock (mbox); |
154 | } | 158 | } |
155 | 159 | ... | ... |
... | @@ -340,6 +340,7 @@ main (int argc, char **argv) | ... | @@ -340,6 +340,7 @@ main (int argc, char **argv) |
340 | mu_alloc_die_hook = pop3d_alloc_die; | 340 | mu_alloc_die_hook = pop3d_alloc_die; |
341 | 341 | ||
342 | mu_log_syslog = 1; | 342 | mu_log_syslog = 1; |
343 | manlock_mandatory_locking = 1; | ||
343 | 344 | ||
344 | if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param, | 345 | if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param, |
345 | argc, argv, 0, NULL, server)) | 346 | argc, argv, 0, NULL, server)) | ... | ... |
-
Please register or sign in to post a comment