summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorJacek Masiulaniec <jacekm@cvs.openbsd.org>2008-12-18 23:57:18 +0000
committerJacek Masiulaniec <jacekm@cvs.openbsd.org>2008-12-18 23:57:18 +0000
commitff67e0a17694010e5eb657df80fb35ebb7032763 (patch)
tree5043b9d11d4300b7c6d8b8cae44b570c7175cb28 /usr.sbin
parentd75806f59369da84e8d7dec88a6b685447914d41 (diff)
Introduce safe_fclose, which tries to push file to the disk as
quickly as possible; it fails under temporary error conditions, letting caller react appropriately. ok gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/smtp_session.c4
-rw-r--r--usr.sbin/smtpd/smtpd.h3
-rw-r--r--usr.sbin/smtpd/util.c22
3 files changed, 25 insertions, 4 deletions
diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c
index a7557c66e1c..4298da03e0b 100644
--- a/usr.sbin/smtpd/smtp_session.c
+++ b/usr.sbin/smtpd/smtp_session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtp_session.c,v 1.30 2008/12/18 23:49:56 jacekm Exp $ */
+/* $OpenBSD: smtp_session.c,v 1.31 2008/12/18 23:57:17 jacekm Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -720,7 +720,7 @@ session_read_data(struct session *s, char *line, size_t nread)
size_t i;
if (strcmp(line, ".") == 0) {
- if (fclose(s->s_msg.datafp))
+ if (! safe_fclose(s->s_msg.datafp))
s->s_msg.status |= S_MESSAGE_TEMPFAILURE;
s->s_msg.datafp = NULL;
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index d0afbd8cbc8..914f527d0dc 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.30 2008/12/18 23:49:56 jacekm Exp $ */
+/* $OpenBSD: smtpd.h,v 1.31 2008/12/18 23:57:17 jacekm Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -766,3 +766,4 @@ struct map *map_findbyname(struct smtpd *, const char *);
/* util.c */
int bsnprintf(char *, size_t, const char *, ...)
__attribute__ ((format (printf, 3, 4)));
+int safe_fclose(FILE *);
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index 17a04f37f9c..07b7faf43ee 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.1 2008/12/11 22:17:12 gilles Exp $ */
+/* $OpenBSD: util.c,v 1.2 2008/12/18 23:57:17 jacekm Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -58,3 +58,23 @@ bsnprintf(char *str, size_t size, const char *format, ...)
return 1;
}
+
+/* Close file, signifying temporary error condition (if any) to the caller. */
+int
+safe_fclose(FILE *fp)
+{
+
+ if (fflush(fp)) {
+ if (errno == ENOSPC)
+ return 0;
+ fatal("safe_fclose: fflush");
+ }
+
+ if (fsync(fileno(fp)))
+ fatal("safe_fclose: fsync");
+
+ if (fclose(fp))
+ fatal("safe_fclose: fclose");
+
+ return 1;
+}