summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2012-01-14 19:35:32 +0000
committerEric Faurot <eric@cvs.openbsd.org>2012-01-14 19:35:32 +0000
commitfbce666840deb52f13eef89907d99dedafc3ec17 (patch)
tree69620cdfac1a238eeab429eebe08ece78f1ad782
parent04d1bd7219f08470490e5a5fdcd59c4c6ba7ae66 (diff)
When moving a message to the corrupt/ directory, give it an alternate name
if there is already an entry with the same name. ok gilles@ chl@
-rw-r--r--usr.sbin/smtpd/queue_fsqueue.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/usr.sbin/smtpd/queue_fsqueue.c b/usr.sbin/smtpd/queue_fsqueue.c
index 2e30425559e..963a6191c65 100644
--- a/usr.sbin/smtpd/queue_fsqueue.c
+++ b/usr.sbin/smtpd/queue_fsqueue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue_fsqueue.c,v 1.33 2012/01/14 12:56:49 eric Exp $ */
+/* $OpenBSD: queue_fsqueue.c,v 1.34 2012/01/14 19:35:31 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -362,11 +362,21 @@ fsqueue_message_delete(enum queue_kind qkind, u_int32_t msgid)
static int
fsqueue_message_corrupt(enum queue_kind qkind, u_int32_t msgid)
{
+ struct stat sb;
char rootdir[MAXPATHLEN];
char corruptdir[MAXPATHLEN];
+ char buf[64];
+ int retry = 0;
fsqueue_message_path(qkind, msgid, rootdir, sizeof(rootdir));
fsqueue_message_path(Q_CORRUPT, msgid, corruptdir, sizeof(corruptdir));
+again:
+ if (stat(corruptdir, &sb) != -1 || errno != ENOENT) {
+ fsqueue_message_path(Q_CORRUPT, msgid, corruptdir, sizeof(corruptdir));
+ snprintf(buf, sizeof(buf), ".%i", retry++);
+ strlcat(corruptdir, buf, sizeof(corruptdir));
+ goto again;
+ }
if (rename(rootdir, corruptdir) == -1)
fatalx("fsqueue_message_corrupt: rename");