From 0f5e2f0ace34e8576f30a4e7fbec8abcc592d854 Mon Sep 17 00:00:00 2001 From: Utsav Munendra Date: Fri, 5 Sep 2025 13:50:36 -0700 Subject: [PATCH] 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 --- lib/xwrap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/xwrap.c b/lib/xwrap.c index cc320af8..6a910230 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -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;