From: Timo Sirainen Date: Tue, 19 May 2009 17:34:54 +0000 (-0400) Subject: safe_sendfile(): Error handling fixes for Linux and Solaris. X-Git-Tag: 2.0.alpha1~727 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5dea9451681f57e1b05bc25d88e04296e5e6ebf7;p=thirdparty%2Fdovecot%2Fcore.git safe_sendfile(): Error handling fixes for Linux and Solaris. --HG-- branch : HEAD --- diff --git a/src/lib/sendfile-util.c b/src/lib/sendfile-util.c index e40efd6121..ff817d16cc 100644 --- a/src/lib/sendfile-util.c +++ b/src/lib/sendfile-util.c @@ -49,12 +49,8 @@ ssize_t safe_sendfile(int out_fd, int in_fd, uoff_t *offset, size_t count) safe_offset = (off_t)*offset; ret = sendfile(out_fd, in_fd, &safe_offset, count); + /* ret=0 : trying to read past EOF, errno = EPIPE : remote is gone */ *offset = (uoff_t)safe_offset; - - if (ret == 0) { - errno = EPIPE; - ret = -1; - } return ret; } @@ -116,7 +112,11 @@ ssize_t safe_sendfile(int out_fd, int in_fd, uoff_t *offset, size_t count) ret = sendfile(out_fd, in_fd, &s_offset, count); if (ret < 0) { - if (errno == EAFNOSUPPORT) { + /* if remote is gone, EPIPE is returned */ + if (errno == EINVAL) { + /* most likely trying to read past EOF */ + ret = 0; + } else if (errno == EAFNOSUPPORT) { /* not supported, return Linux-like EINVAL so caller sees only consistent errnos. */ errno = EINVAL;