From fbce666840deb52f13eef89907d99dedafc3ec17 Mon Sep 17 00:00:00 2001 From: Eric Faurot Date: Sat, 14 Jan 2012 19:35:32 +0000 Subject: 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@ --- usr.sbin/smtpd/queue_fsqueue.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 @@ -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"); -- cgit v1.2.3