dovecot: If file_set_size() fails for any other reason than "not...

dovecot at dovecot.org dovecot at dovecot.org
Sat Oct 20 20:51:35 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/b7d8695d864d
changeset: 6569:b7d8695d864d
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Oct 20 20:51:30 2007 +0300
description:
If file_set_size() fails for any other reason than "not enough disk
space/quota", log the syscall that caused the error.

diffstat:

1 file changed, 20 insertions(+), 6 deletions(-)
src/lib/file-set-size.c |   26 ++++++++++++++++++++------

diffs (51 lines):

diff -r 717fdce1cfb4 -r b7d8695d864d src/lib/file-set-size.c
--- a/src/lib/file-set-size.c	Sat Oct 20 20:45:05 2007 +0300
+++ b/src/lib/file-set-size.c	Sat Oct 20 20:51:30 2007 +0300
@@ -19,16 +19,27 @@ int file_set_size(int fd, off_t size)
 
 	i_assert(size >= 0);
 
-	if (fstat(fd, &st) < 0)
+	if (fstat(fd, &st) < 0) {
+		i_error("fstat() failed: %m");
 		return -1;
+	}
 
-	if (size < st.st_size)
-		return ftruncate(fd, size);
+	if (size < st.st_size) {
+		if (ftruncate(fd, size) < 0) {
+			i_error("ftruncate() failed: %m");
+			return -1;
+		}
+		return 0;
+	}
 	if (size == st.st_size)
 		return 0;
 
 #ifdef HAVE_POSIX_FALLOCATE
-	return posix_fallocate(fd, st.st_size, size - st.st_size);
+	if (posix_fallocate(fd, st.st_size, size - st.st_size) < 0) {
+		if (!ENOSPACE(errno))
+			i_error("posix_fallocate() failed: %m");
+		return -1;
+	}
 #else
 	/* start growing the file */
 	offset = st.st_size;
@@ -38,10 +49,13 @@ int file_set_size(int fd, off_t size)
 		ret = pwrite(fd, block,
 			     I_MIN((ssize_t)sizeof(block), size - offset),
 			     offset);
-		if (ret < 0)
+		if (ret < 0) {
+			if (!ENOSPACE(errno))
+				i_error("pwrite() failed: %m");
 			return -1;
+		}
 		offset += size;
 	}
+#endif
 	return 0;
-#endif
 }


More information about the dovecot-cvs mailing list