summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Wilson <alex@cooperi.net>2020-08-29 00:29:58 +1000
committerGitHub <noreply@github.com>2020-08-28 10:29:58 -0400
commitb189ef943db9b29af9068d3b3b49bc364699da56 (patch)
tree0390da7d06af97db35f3703cb28acab04b727cf1
parent8c51cef461435cad4226b140906d767b91d54923 (diff)
downloadillumos-joyent-b189ef943db9b29af9068d3b3b49bc364699da56.tar.gz
joyent/illumos-joyent#326 LX sendfile returns EINVAL at EOF when it should return 0 (#327)
Reviewed by: Andy Fiddaman <andy@omniosce.org> Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r--usr/src/lib/brand/lx/lx_brand/common/sendfile.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/usr/src/lib/brand/lx/lx_brand/common/sendfile.c b/usr/src/lib/brand/lx/lx_brand/common/sendfile.c
index c09e8c51dc..7b87958ac0 100644
--- a/usr/src/lib/brand/lx/lx_brand/common/sendfile.c
+++ b/usr/src/lib/brand/lx/lx_brand/common/sendfile.c
@@ -38,6 +38,7 @@
#include <errno.h>
#include <sys/lx_misc.h>
#include <sys/lx_syscall.h>
+#include <sys/stat.h>
#if defined(_ILP32)
long
@@ -73,6 +74,18 @@ lx_sendfile(uintptr_t p1, uintptr_t p2, uintptr_t p3, uintptr_t p4)
if (xferred > 0) {
error = 0;
}
+ /*
+ * If we got EINVAL due to our offset being past EOF, also suppress
+ * errors (Linux just returns 0 here).
+ */
+ if (error == EINVAL) {
+ struct stat stat;
+ if (fstat((int)p2, &stat) == 0) {
+ if (off >= stat.st_size) {
+ error = 0;
+ }
+ }
+ }
if (error == 0) {
off += xferred;
@@ -125,6 +138,18 @@ lx_sendfile64(uintptr_t p1, uintptr_t p2, uintptr_t p3, uintptr_t p4)
if (xferred > 0) {
error = 0;
}
+ /*
+ * If we got EINVAL due to our offset being past EOF, also suppress
+ * errors (Linux just returns 0 here).
+ */
+ if (error == EINVAL) {
+ struct stat stat;
+ if (fstat((int)p2, &stat) == 0) {
+ if (off >= stat.st_size) {
+ error = 0;
+ }
+ }
+ }
if (error == 0) {
off += xferred;