Robin Bowes writes:
You need to put the whole thing under an flock, and trap exceptions
only from the maildirmake process.
How about something like this:
You're missing the point. Consider two delivery attempts running
simultaneously, the mailing list folder does not exist.
if ( this is a mailing list )
{
exception {
to "${VMAILDIR}/.${LISTS}.${MATCH2}/"
}
First of all, as you know, if the file does not exist, maildrop, for legacy
reasons, creates an mbox file.
You want, instead: to "${VMAILDIR}/.${LISTS}.${MATCH2}/."
Anyway, with that correction in place, both delivery attempts fail here, and
fall through.
exception {
flock lockfile_${MATCH2} {
`${MAILDIRMAKE} -f ${LISTS}.${MATCH2} ${VMAILDIR}`
}
Delivery attempt #1 grabs the lock. Delivery attempt #2 waits for the lock
to be released. Delivery attempt #1 creates the folder, releases the lock.
Then, delivery attempt takes the lock that it's been waiting on, and tries
to create the folder itself, and fails, and the exception falls through, and
the message is not delivered.
When flock cannot take the lock immediately, it waits for the lock to be
released. Once the lock is obtained it STILL executed the instructions
inside the flock statement. That's what you need to remember.