aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2026-02-11 16:24:46 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2026-02-11 16:24:46 +0000
commit7aa30669d6e04444b8ad1e4863a6e674fcac4afc (patch)
tree2de3a68c0a51b649e042c23a3e82058ccb91ba9d
parent89589b6d3fbac43eb7c6b3cdbdd6f077888b2142 (diff)
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
-rw-r--r--bin/cp/utils.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index 2036056ada68..2579ea0a9603 100644
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -216,7 +216,10 @@ copy_file(const FTSENT *entp, bool dne, bool beneath)
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,
@@ -224,7 +227,7 @@ copy_file(const FTSENT *entp, bool dne, bool beneath)
entp->fts_path, to.base, to.path,
cp_pct(wtotal, fs->st_size));
}
- } while (wcount > 0);
+ } while (wcount != 0);
if (wcount < 0) {
warn("%s", entp->fts_path);
rval = 1;