Re: Possible problem with zero-copy TCP and sendfile()

Jan Kasprzak
2001-04-17T20:37:01Z

Jesse S Sipprell wrote:
: After cursory examination of proftpd, it appears that there is a misuse of the
: sendfile() call under Linux, which may be responsible for the corruption. The
: code was originally based on BSD semantics. Under Linux, the offset argument
: is not being used correctly to determine how much data has been sent in the
: case of EINTR.
:
: A patch will be coming out soon, as it is a fairly trivial fix.
:
FWIW, I've fixed ProFTPd on my server with the following patch.
Sorry for making noise @ linux-kernel list, it was totally unrelated
to the Linux kernel:

--- proftpd-1.2.2rc1/src/data.c.sendfile Thu Feb 15 15:24:53 2001
+++ proftpd-1.2.2rc1/src/data.c Tue Apr 17 21:35:24 2001
@@ -760,7 +760,9 @@
*
* ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count)
*/
- if((len = sendfile(session.d->outf->fd, retr_fd, offset, count)) == -1) {
+ len = sendfile(session.d->outf->fd, retr_fd, offset, count);
+ if (len == -1 || len > 0 && len < count) {
+ errno = EINTR;
#elif defined(HAVE_BSD_SENDFILE)
/* BSD semantics for sendfile are flexible...it'd be nice if we could
* standardize on something like it. The semantics are:
@@ -797,7 +799,9 @@
if((count -= len) <= 0)
break;

+#if !defined(HAVE_LINUX_SENDFILE)
*offset += len;
+#endif

if(TimeoutStalled)
reset_timer(TIMER_STALLED, ANY_MODULE);

-Yenya

--
\ Jan "Yenya" Kasprzak <kas at fi.muni.cz> http://www.fi.muni.cz/~kas/
\\ PGP: finger kas at aisa.fi.muni.cz 0D99A7FB206605D7 8B35FCDE05B18A5E //
\\\ Czech Linux Homepage: http://www.linux.cz/ ///
Mantra: "everything is a stream of bytes". Repeat until enlightened. --Linus