git: bdd021191274 - stable/14 - pw: Use copy_file_range() when copying skeleton files
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 05 Oct 2025 13:13:33 UTC
The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=bdd021191274d70bf9a2f752f45f76501321cdde commit bdd021191274d70bf9a2f752f45f76501321cdde Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2025-09-18 22:39:39 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2025-10-05 13:13:01 +0000 pw: Use copy_file_range() when copying skeleton files As a bonus, check for I/O errors and print them to standard error. Reviewed by: bapt, emaste MFC after: 1 week Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D52588 (cherry picked from commit a03d150a3d44c49344ebd0862defd1a5ad1f524e) --- usr.sbin/pw/cpdir.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/usr.sbin/pw/cpdir.c b/usr.sbin/pw/cpdir.c index 63068cab000c..3839a039495a 100644 --- a/usr.sbin/pw/cpdir.c +++ b/usr.sbin/pw/cpdir.c @@ -36,10 +36,10 @@ #include "pw.h" void -copymkdir(int rootfd, char const * dir, int skelfd, mode_t mode, uid_t uid, +copymkdir(int rootfd, char const *dir, int skelfd, mode_t mode, uid_t uid, gid_t gid, int flags) { - char *p, lnk[MAXPATHLEN], copybuf[4096]; + char *p, lnk[MAXPATHLEN]; int len, homefd, srcfd, destfd; ssize_t sz; struct stat st; @@ -120,8 +120,12 @@ copymkdir(int rootfd, char const * dir, int skelfd, mode_t mode, uid_t uid, continue; } - while ((sz = read(srcfd, copybuf, sizeof(copybuf))) > 0) - write(destfd, copybuf, sz); + do { + sz = copy_file_range(srcfd, NULL, destfd, NULL, + SSIZE_MAX, 0); + } while (sz > 0); + if (sz < 0) + warn("copy_file_range"); close(srcfd); /*