epg [Sun, 19 Jan 2003 03:11:14 +0000 (03:11 +0000)]
mdeliver/current/mdeliver.c:
(deliver): In rev 1582 i changed this from using rename(2) to
the recommended link(2) + unlink(2). But in minc i was using
open(2) + rename(2) instead, which is just as safe as link +
unlink but with one advantage. So switch to that model.
minc/current/minc:
(store_message): Document the open + rename procedure and
explain why it is used instead of link + unlink.
epg [Thu, 16 Jan 2003 17:59:18 +0000 (17:59 +0000)]
(deliver): Stick closer to the standard maildir delivery algorithm by
using link(2) + unlink(2) instead of rename(2) to get the message file
from tmp to new. rename(2) will clobber an existing file, which we
don't want; link(2) will not.
Strictly speaking this is an impossible scenario for mdeliver, for
which one process delivers no more than one message. It is, however,
not outside the realm of possibility that a filename identical to the
one chosen by mdeliver came into existence for some unrelated reason
(though the odds of this happening must be staggering).
Perhaps more importantly, it has been reported on the qmail list that
OpenBSD 3.2 will reuse the same PID in the same second, which would
mean this was a real problem on that system.
Whatever the case, this addresses any potential problems.
(run_processor): While there's nothing we can do if any of the
err-file-writing steps fail, there's no reason we can't be a little
more careful in doing it. Do so (including using fflush, fsync,
and close).
(run_processor): Now only takes a single argument, the filename of the
new message. The process to run is now hard-coded to be a dot-file in
the user's home directory.
Rename copy_message to copy_file, document it, and make it slightly
more generic. Now i can share it with other programs (for example, my
portable install(1)).
Only include <sysexits.h> if MDELIVER_EXITCODE is not defined, and if
it isn't defined, define it to EX_TEMPFAIL. Change all references to
EX_TEMPFAIL to MDELIVER_EXITCODE.