summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacek Masiulaniec <jacekm@cvs.openbsd.org>2008-12-29 09:03:26 +0000
committerJacek Masiulaniec <jacekm@cvs.openbsd.org>2008-12-29 09:03:26 +0000
commitb9d66a2dc6f6a73c3cabbc61f48a1b2f14ef7f7e (patch)
treebdbd0ae356d5a9ce685e78adb0f781a318d420c9
parentcb7a5b3c3f14f78ed7b5cbd9a01a1070c2187c86 (diff)
Handle ENOSPC in queue_update_envelope; cleanup the code a bit; ok gilles@
-rw-r--r--usr.sbin/smtpd/queue.c32
1 files changed, 11 insertions, 21 deletions
diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c
index 94bf719b126..654cf6b01a4 100644
--- a/usr.sbin/smtpd/queue.c
+++ b/usr.sbin/smtpd/queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue.c,v 1.35 2008/12/27 18:18:33 jacekm Exp $ */
+/* $OpenBSD: queue.c,v 1.36 2008/12/29 09:03:25 jacekm Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -956,35 +956,25 @@ queue_remove_envelope(struct message *messagep)
int
queue_update_envelope(struct message *messagep)
{
- int fd;
char pathname[MAXPATHLEN];
FILE *fp;
- mode_t mode = O_RDWR;
- u_int16_t hval;
-
- hval = queue_hash(messagep->message_id);
if (! bsnprintf(pathname, MAXPATHLEN, "%s/%d/%s%s/%s", PATH_QUEUE,
- hval, messagep->message_id, PATH_ENVELOPES, messagep->message_uid))
+ queue_hash(messagep->message_id), messagep->message_id,
+ PATH_ENVELOPES, messagep->message_uid))
fatal("queue_update_envelope: snprintf");
- if ((fd = open(pathname, mode)) == -1)
+ fp = fopen(pathname, "w");
+ if (fp == NULL)
fatal("queue_update_envelope: open");
-
- if (flock(fd, LOCK_EX) == -1)
+ if (flock(fileno(fp), LOCK_EX) == -1)
fatal("queue_update_envelope: flock");
-
- fp = fdopen(fd, "w");
- if (fp == NULL)
- fatal("queue_update_envelope: fdopen");
-
- if (fwrite(messagep, sizeof(struct message), 1, fp) != 1)
+ if (fwrite(messagep, sizeof(struct message), 1, fp) != 1) {
+ if (errno == ENOSPC)
+ return 0;
fatal("queue_update_envelope: fwrite");
- fflush(fp);
- fsync(fd);
- fclose(fp);
-
- return 1;
+ }
+ return safe_fclose(fp);
}
int