git: 91a805447374 - stable/14 - linux sendfile: Fix handling of non-blocking sockets
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 20 Nov 2024 21:41:15 UTC
The branch stable/14 has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=91a80544737486dbe5bbae28c05c2a7a654cb61f
commit 91a80544737486dbe5bbae28c05c2a7a654cb61f
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-11-13 14:15:47 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-11-20 21:41:08 +0000
linux sendfile: Fix handling of non-blocking sockets
FreeBSD sendfile() may perform a partial transfer and return EAGAIN if
the socket is non-blocking. Linux sendfile() expects no error in this
case, so squash EAGAIN.
PR: 282495
Tested by: pieter@krikkit.xyz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D47447
(cherry picked from commit a43b745aaf4f5bbc96875d2ab3ec9bea8024eda4)
---
sys/compat/linux/linux_socket.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c
index 705a64de8ede..d35ff37aee98 100644
--- a/sys/compat/linux/linux_socket.c
+++ b/sys/compat/linux/linux_socket.c
@@ -2537,6 +2537,13 @@ sendfile_sendfile(struct thread *td, struct file *fp, l_int out,
current_offset = *offset;
error = fo_sendfile(fp, out, NULL, NULL, current_offset, count,
sbytes, 0, td);
+ if (error == EAGAIN && *sbytes > 0) {
+ /*
+ * The socket is non-blocking and we didn't finish sending.
+ * Squash the error, since that's what Linux does.
+ */
+ error = 0;
+ }
if (error == 0) {
current_offset += *sbytes;
if (offset != NULL)