git: f1a86b35dedb - stable/13 - cp: Expect EINTR while copying

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Sun, 15 Feb 2026 08:58:54 UTC
The branch stable/13 has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=f1a86b35dedba1b7dfa0ec8dae63b08a76cd395a

commit f1a86b35dedba1b7dfa0ec8dae63b08a76cd395a
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-11 16:24:46 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-02-15 08:58:45 +0000

    cp: Expect EINTR while copying
    
    Both copy_file_range() and copy_fallback() can be interrupted before
    they have read anything at all, in which case they return -1 and set
    errno to EINTR.  If that happens, we should retry, not fail.
    
    PR:             293028
    MFC after:      1 week
    Reviewed by:    kevans
    Differential Revision:  https://reviews.freebsd.org/D55167
    
    (cherry picked from commit 7aa30669d6e04444b8ad1e4863a6e674fcac4afc)
---
 bin/cp/utils.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index 9f6ef888c7ea..7590d7d3ee1d 100644
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -213,7 +213,10 @@ copy_file(const FTSENT *entp, int dne)
 		if (!use_copy_file_range) {
 			wcount = copy_fallback(from_fd, to_fd);
 		}
-		wtotal += wcount;
+		if (wcount >= 0)
+			wtotal += wcount;
+		else if (errno != EINTR)
+			break;
 		if (info) {
 			info = 0;
 			(void)fprintf(stderr,
@@ -221,7 +224,7 @@ copy_file(const FTSENT *entp, int dne)
 			    entp->fts_path, to.p_path,
 			    cp_pct(wtotal, fs->st_size));
 		}
-	} while (wcount > 0);
+	} while (wcount != 0);
 	if (wcount < 0) {
 		warn("%s", entp->fts_path);
 		rval = 1;