]> diplodocus.org Git - mdeliver/commitdiff
(deliver): Stick closer to the standard maildir delivery algorithm by
authorepg <>
Thu, 16 Jan 2003 17:59:18 +0000 (17:59 +0000)
committerepg <>
Thu, 16 Jan 2003 17:59:18 +0000 (17:59 +0000)
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.

mdeliver.c

index c2e7d06d62aad0df83afec6523455e960cf445c9..54884e98e35ecbc0211b68b450b3aa912bec4111 100644 (file)
@@ -243,10 +243,12 @@ deliver(char *maildir, char *newfn)
     strcpy(newfn, fn);
     memcpy(newfn, "new", 3);
 
     strcpy(newfn, fn);
     memcpy(newfn, "new", 3);
 
-    if (rename(fn, newfn) != 0) {
+    if (link(fn, newfn) != 0) {
         save_errno( unlink(fn) );
         save_errno( unlink(fn) );
-        err(MDELIVER_EXITCODE, "Failed rename(%s, new)", fn);
+        err(MDELIVER_EXITCODE, "Failed link(%s, new)", fn);
     }
     }
+
+    unlink(fn);
 }
 
 /* Run a program to process the new message. */
 }
 
 /* Run a program to process the new message. */