From 186e347f2ce38657cec972b2a8283030e4e48ee8 Mon Sep 17 00:00:00 2001 From: David Greenman Date: Mon, 1 Dec 2003 22:12:50 +0000 Subject: [PATCH] Fixed a bug in sendfile(2) where the sent data would be corrupted due to sendfile(2) being erroneously automatically restarted after a signal is delivered. Fixed by converting ERESTART to EINTR prior to exiting. Updated manual page to indicate the potential EINTR error, its cause and consequences. Approved by: re@freebsd.org --- lib/libc/sys/sendfile.2 | 8 ++++++-- sys/kern/uipc_syscalls.c | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/libc/sys/sendfile.2 b/lib/libc/sys/sendfile.2 index 96979eed5a7..e2cac6a4a77 100644 --- a/lib/libc/sys/sendfile.2 +++ b/lib/libc/sys/sendfile.2 @@ -1,4 +1,4 @@ -.\" Copyright (c) 1998, David Greenman +.\" Copyright (c) 2003, David G. Lawrence .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -191,6 +191,10 @@ An error occurred while reading from .Fa fd . .It Bq Er EFAULT An invalid address was specified for an argument. +.It Bq Er EINTR +A signal interrupted sendfile before it could be completed. If specified, the number +of bytes successfully sent will be returned in +.Fa *sbytes . .It Bq Er EAGAIN The socket is marked for non-blocking I/O and not all data was sent due to the socket buffer being filled. If specified, the number of bytes successfully sent will be returned in @@ -215,4 +219,4 @@ The .Fn sendfile system call and this manual page were written by -.An David Greenman Aq dg@root.com . +.An David G. Lawrence Aq dg@dglawrence.com . diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 0e52d4b77ca..135ae1ddcfb 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1994,6 +1994,11 @@ done: vrele(vp); if (so) fputsock(so); + mtx_unlock(&Giant); + + if (error == ERESTART) + error = EINTR; + return (error); }