From: Ian Lance Taylor Date: Thu, 12 Dec 2024 22:07:13 +0000 (-0800) Subject: syscall: on freebsd-386 only update written for certain errors X-Git-Tag: go1.24rc2~6^2~101 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=38e9a671d7;p=gostls13.git syscall: on freebsd-386 only update written for certain errors 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 Commit-Queue: Ian Lance Taylor Reviewed-by: Damien Neil LUCI-TryBot-Result: Go LUCI Auto-Submit: Ian Lance Taylor --- diff --git a/src/syscall/syscall_freebsd_386.go b/src/syscall/syscall_freebsd_386.go index 60359e38f6..a217dc758b 100644 --- a/src/syscall/syscall_freebsd_386.go +++ b/src/syscall/syscall_freebsd_386.go @@ -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