xsendfile_len() to exit with error if underlying write fails

cp currently will exit with success even if the underlying
write syscall fails with an error. Fixing this behavior.

Signed-off-by: Utsav Munendra <utsavm@meta.com>
This commit is contained in:
Utsav Munendra 2025-09-05 13:50:36 -07:00 committed by Rob Landley
parent 494f9c4efc
commit 0f5e2f0ace

View File

@ -867,9 +867,9 @@ long long xsendfile_len(int in, int out, long long bytes)
{
long long len = sendfile_len(in, out, bytes, 0);
if (bytes != -1 && bytes != len) {
if (len == -1 || (bytes != -1 && bytes != len)) {
if (out == 1 && len<0) xexit();
error_exit("short %s", (len<0) ? "write" : "read");
perror_exit("short %s", (len<0) ? "write" : "read");
}
return len;