Skip to content

Report source read errors from fsendfile - #24

Closed
omrzk wants to merge 1 commit into
troglobit:masterfrom
omrzk:fix/report-fsendfile-read-errors
Closed

omrzk wants to merge 1 commit into
troglobit:masterfrom
omrzk:fix/report-fsendfile-read-errors

Conversation

@omrzk

@omrzk omrzk commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

fsendfile() treats a failed fread() like EOF and returns a successful byte count, including when a nonblocking pipe has no data or runs out after a partial transfer. This contradicts its documented -1 error return and affects both copying and the supported discard mode.

Check the source stream's error indicator and preserve errno across buffer cleanup. Keep copied bytes and caller ownership of both streams intact, so callers can clear the source error and resume.

Validation: the new real-pipe regression fails on current master and passes with the fix. It covers initial/partial read errors with finite/unlimited lengths, copy/discard modes and clear-error reuse; controls cover exact-length reads without EOF, binary data across buffer boundaries, stream offsets, EOF, invalid arguments and an unbuffered /dev/full write failure. Strict GCC and ASan/UBSan/LeakSanitizer checks pass. GCC 13 full build passes. Full make check passes 23 of 24 tests; pidfile cannot write /var/tmp here, reproduced using the exact current master test and dependencies. make distcheck includes and passes the new regression, then hits the same limitation; native Clang, Debian packaging and other operating systems were not tested locally. Buffered destination flush errors remain the caller's responsibility.

@troglobit troglobit closed this in 8befd09 Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant