]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: on freebsd-386 only update written for certain errors
authorIan Lance Taylor <iant@golang.org>
Thu, 12 Dec 2024 22:07:13 +0000 (14:07 -0800)
committerGopher Robot <gobot@golang.org>
Thu, 12 Dec 2024 22:43:37 +0000 (14:43 -0800)
Testing on the freebsd-386 gomote seems to show that sendfile returns
a non-zero number of bytes written even when it returns EINVAL.
This confuses the caller. Change the Go code to only return non-zero
on success or EINTR or EAGAIN, which are the only cases where the
man page says that sendfile updates the number of bytes.

For #70763

Change-Id: Icc04e6286b5b29a2029237711d50fe4973234f0a
Reviewed-on: https://go-review.googlesource.com/c/go/+/635815
Reviewed-by: Ian Lance Taylor <iant@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/syscall/syscall_freebsd_386.go

index 60359e38f6b50db2769d1e4e1a2fa530097996ea..a217dc758b904f4924a7b4d148ffe8e8c4087875 100644 (file)
@@ -36,7 +36,13 @@ func sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
        var writtenOut uint64 = 0
        _, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr((*offset)>>32), uintptr(count), 0, uintptr(unsafe.Pointer(&writtenOut)), 0, 0)
 
-       written = int(writtenOut)
+       // For some reason on the freebsd-386 builder writtenOut
+       // is modified when the system call returns EINVAL.
+       // The man page says that the value is only written for
+       // success, EINTR, or EAGAIN, so only use those cases.
+       if e1 == 0 || e1 == EINTR || e1 == EAGAIN {
+               written = int(writtenOut)
+       }
 
        if e1 != 0 {
                err = e1