Avoid race condition when receiving incoming mails
[onak.git] / onak-mail.pl.in
index 77a3d3677de9174f42587601bf8bb802be8894bf..96fce71008e10bf178d5e5d7ac67f34e80414b6e 100644 (file)
@@ -212,11 +212,12 @@ my $tmpfile = sprintf "%s/%04d%02d%02d-%02d%02d%02d-%d.onak",
                        $time[1],
                        $time[0],
                        $$;
-open(MAILFILE, '>'.$tmpfile);
+open(MAILFILE, '>'.$tmpfile.'.tmp');
 while (<>) {
        print MAILFILE $_;
 }
 close(MAILFILE);
+rename $tmpfile.".tmp", $tmpfile;
 
 #
 # Lock here to ensure that only one copy of us is processing the incoming