changeset 311:2cb72f8e0998 HEAD

io_buffer_send_iobuffer() didn't set buf_errno if sendfile() failed.
author Timo Sirainen <tss@iki.fi>
date Tue, 24 Sep 2002 19:36:52 +0300
parents 98e62bc03363
children f5e59d65d124
files src/lib/iobuffer.c
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/iobuffer.c	Tue Sep 24 19:17:39 2002 +0300
+++ b/src/lib/iobuffer.c	Tue Sep 24 19:36:52 2002 +0300
@@ -497,8 +497,10 @@
 	ret = safe_sendfile(ctx->outbuf->fd, ctx->inbuf->fd, &offset,
 			    MAX_SSIZE_T(ctx->size));
 	if (ret < 0) {
-		if (errno != EINTR && errno != EAGAIN)
+		if (errno != EINTR && errno != EAGAIN) {
+			ctx->outbuf->buf_errno = errno;
 			ctx->outbuf->closed = TRUE;
+		}
 		ret = 0;
 	}
 
@@ -526,8 +528,10 @@
 	ret = safe_sendfile(outbuf->fd, inbuf->fd, &offset,
 			    MAX_SSIZE_T(long_size));
 	if (ret < 0) {
-		if (errno != EINTR && errno != EAGAIN)
+		if (errno != EINTR && errno != EAGAIN) {
+			outbuf->buf_errno = errno;
 			return -1;
+		}
 		ret = 0;
 	}
 
@@ -545,10 +549,10 @@
 	ctx.size = long_size - ret;
 
 	ret = io_buffer_ioloop(outbuf, &ctx, block_loop_sendfile);
-	if (ret < 0 && errno == EINVAL) {
+	if (ret < 0 && outbuf->buf_errno == EINVAL) {
 		/* this shouldn't happen, must be a bug. It would also
 		   mess up later if we let this pass. */
-		i_fatal("io_buffer_sendfile() failed: %m");
+		i_panic("io_buffer_sendfile() failed: %m");
 	}
 	return ret;
 }
@@ -588,7 +592,7 @@
 	i_assert(inbuf->limit > 0 || size <= inbuf->limit - inbuf->offset);
 
 	ret = io_buffer_sendfile(outbuf, inbuf, size);
-	if (ret > 0 || errno != EINVAL)
+	if (ret > 0 || outbuf->buf_errno != EINVAL)
 		return ret < 0 ? -1 : 1;
 
 	/* sendfile() not supported (with this fd), fallback to