dovecot-2.0: zlib: Improved error message logging. Log input str...

dovecot at dovecot.org dovecot at dovecot.org
Sat Mar 6 14:05:34 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/257556760b62
changeset: 10850:257556760b62
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Mar 06 14:05:25 2010 +0200
description:
zlib: Improved error message logging. Log input stream names.

diffstat:

 src/plugins/zlib/istream-bzlib.c |  28 +++++++++++++++++++++-------
 src/plugins/zlib/istream-zlib.c  |  40 ++++++++++++++++++++++++++++------------
 2 files changed, 49 insertions(+), 19 deletions(-)

diffs (171 lines):

diff -r 638c4ea4a9ce -r 257556760b62 src/plugins/zlib/istream-bzlib.c
--- a/src/plugins/zlib/istream-bzlib.c	Sat Mar 06 14:04:42 2010 +0200
+++ b/src/plugins/zlib/istream-bzlib.c	Sat Mar 06 14:05:25 2010 +0200
@@ -32,6 +32,14 @@
 	}
 }
 
+static void bzlib_read_error(struct bzlib_istream *zstream, const char *error)
+{
+	i_error("bzlib.read(%s): %s at %"PRIuUOFF_T,
+		i_stream_get_name(&zstream->istream.istream), error,
+		zstream->istream.abs_start_offset +
+		zstream->istream.istream.v_offset);
+}
+
 static ssize_t i_stream_bzlib_read(struct istream_private *stream)
 {
 	struct bzlib_istream *zstream = (struct bzlib_istream *)stream;
@@ -78,8 +86,10 @@
 					stream->parent->stream_errno;
 			} else {
 				i_assert(stream->parent->eof);
-				if (zstream->log_errors)
-					i_error("bzlib: unexpected EOF");
+				if (zstream->log_errors) {
+					bzlib_read_error(zstream,
+							 "unexpected EOF");
+				}
 				stream->istream.stream_errno = EINVAL;
 			}
 			return -1;
@@ -110,16 +120,19 @@
 		i_unreached();
 	case BZ_DATA_ERROR:
 		if (zstream->log_errors)
-			i_error("bzlib: corrupted data");
+			bzlib_read_error(zstream, "corrupted data");
 		stream->istream.stream_errno = EINVAL;
 		return -1;
 	case BZ_DATA_ERROR_MAGIC:
-		if (zstream->log_errors)
-			i_error("bzlib: wrong magic in header (not bz2 file?)");
+		if (zstream->log_errors) {
+			bzlib_read_error(zstream,
+				"wrong magic in header (not bz2 file?)");
+		}
 		stream->istream.stream_errno = EINVAL;
 		return -1;
 	case BZ_MEM_ERROR:
-		i_fatal_status(FATAL_OUTOFMEM, "bzlib: Out of memory");
+		i_fatal_status(FATAL_OUTOFMEM, "bzlib.read(%s): Out of memory",
+			       i_stream_get_name(&stream->istream));
 	case BZ_STREAM_END:
 		zstream->eof_offset = stream->istream.v_offset + stream->pos;
 		if (size == 0) {
@@ -206,7 +219,8 @@
 		if (stream->istream.v_offset != v_offset) {
 			/* some failure, we've broken it */
 			if (stream->istream.stream_errno != 0) {
-				i_error("bzlib_istream.seek() failed: %s",
+				i_error("bzlib_istream.seek(%s) failed: %s",
+					i_stream_get_name(&stream->istream),
 					strerror(stream->istream.stream_errno));
 				i_stream_close(&stream->istream);
 			} else {
diff -r 638c4ea4a9ce -r 257556760b62 src/plugins/zlib/istream-zlib.c
--- a/src/plugins/zlib/istream-zlib.c	Sat Mar 06 14:04:42 2010 +0200
+++ b/src/plugins/zlib/istream-zlib.c	Sat Mar 06 14:05:25 2010 +0200
@@ -47,6 +47,14 @@
 	}
 }
 
+static void zlib_read_error(struct zlib_istream *zstream, const char *error)
+{
+	i_error("zlib.read(%s): %s at %"PRIuUOFF_T,
+		i_stream_get_name(&zstream->istream.istream), error,
+		zstream->istream.abs_start_offset +
+		zstream->istream.istream.v_offset);
+}
+
 static int i_stream_zlib_read_header(struct istream_private *stream)
 {
 	struct zlib_istream *zstream = (struct zlib_istream *)stream;
@@ -60,7 +68,7 @@
 	if (size == zstream->prev_size) {
 		if (ret == -1) {
 			if (zstream->log_errors)
-				i_error("zlib: missing gz header");
+				zlib_read_error(zstream, "missing gz header");
 			stream->istream.stream_errno = EINVAL;
 		}
 		return ret;
@@ -73,8 +81,10 @@
 
 	if (data[0] != GZ_MAGIC1 || data[1] != GZ_MAGIC2) {
 		/* missing gzip magic header */
-		if (zstream->log_errors)
-			i_error("zlib: wrong magic in header (not gz file?)");
+		if (zstream->log_errors) {
+			zlib_read_error(zstream, "wrong magic in header "
+					"(not gz file?)");
+		}
 		stream->istream.stream_errno = EINVAL;
 		return -1;
 	}
@@ -127,7 +137,7 @@
 	if (size == zstream->prev_size) {
 		if (ret == -1) {
 			if (zstream->log_errors)
-				i_error("zlib: missing gz trailer");
+				zlib_read_error(zstream, "missing gz trailer");
 			stream->istream.stream_errno = EINVAL;
 		}
 		return ret;
@@ -138,8 +148,10 @@
 		return 0;
 
 	if (data_get_uint32(data) != zstream->crc32) {
-		if (zstream->log_errors)
-			i_error("zlib: gz trailer has wrong CRC value");
+		if (zstream->log_errors) {
+			zlib_read_error(zstream,
+					"gz trailer has wrong CRC value");
+		}
 		stream->istream.stream_errno = EINVAL;
 		return -1;
 	}
@@ -211,8 +223,10 @@
 					stream->parent->stream_errno;
 			} else {
 				i_assert(stream->parent->eof);
-				if (zstream->log_errors)
-					i_error("zlib: unexpected EOF");
+				if (zstream->log_errors) {
+					zlib_read_error(zstream,
+							"unexpected EOF");
+				}
 				stream->istream.stream_errno = EINVAL;
 			}
 			return -1;
@@ -243,16 +257,17 @@
 		break;
 	case Z_NEED_DICT:
 		if (zstream->log_errors)
-			i_error("zlib: can't read file without dict");
+			zlib_read_error(zstream, "can't read file without dict");
 		stream->istream.stream_errno = EINVAL;
 		return -1;
 	case Z_DATA_ERROR:
 		if (zstream->log_errors)
-			i_error("zlib: corrupted data");
+			zlib_read_error(zstream, "corrupted data");
 		stream->istream.stream_errno = EINVAL;
 		return -1;
 	case Z_MEM_ERROR:
-		i_fatal_status(FATAL_OUTOFMEM, "zlib: Out of memory");
+		i_fatal_status(FATAL_OUTOFMEM, "zlib.read(%s): Out of memory",
+			       i_stream_get_name(&stream->istream));
 	case Z_STREAM_END:
 		zstream->eof_offset = stream->istream.v_offset + stream->pos;
 		i_stream_skip(stream->parent,
@@ -350,7 +365,8 @@
 		if (stream->istream.v_offset != v_offset) {
 			/* some failure, we've broken it */
 			if (stream->istream.stream_errno != 0) {
-				i_error("zlib_istream.seek() failed: %s",
+				i_error("zlib_istream.seek(%s) failed: %s",
+					i_stream_get_name(&stream->istream),
 					strerror(stream->istream.stream_errno));
 				i_stream_close(&stream->istream);
 			} else {


More information about the dovecot-cvs mailing list