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
This commit is contained in:
Dag-Erling Smørgrav
2026-02-11 17:24:46 +01:00
parent 89589b6d3f
commit 7aa30669d6
+5 -2
View File
@@ -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;