git: 239fb1ad8e73 - stable/14 - pw: Print warnings when metadata updates fail

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Sun, 05 Oct 2025 13:13:29 UTC
The branch stable/14 has been updated by markj:

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

commit 239fb1ad8e7336f4c9208828d926525be763d374
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-09-18 22:38:33 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-10-05 13:13:00 +0000

    pw: Print warnings when metadata updates fail
    
    We do this in most places already, but not consistently.
    
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Sponsored by:   Klara, Inc.
    
    (cherry picked from commit daa63c9417a28ad08881ff03df828fd8180dad12)
---
 usr.sbin/pw/cpdir.c   | 6 ++++--
 usr.sbin/pw/pw_user.c | 3 ++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/usr.sbin/pw/cpdir.c b/usr.sbin/pw/cpdir.c
index 3dee8f7c43ac..63068cab000c 100644
--- a/usr.sbin/pw/cpdir.c
+++ b/usr.sbin/pw/cpdir.c
@@ -127,8 +127,10 @@ copymkdir(int rootfd, char const * dir, int skelfd, mode_t mode, uid_t uid,
 		/*
 		 * Propagate special filesystem flags
 		 */
-		fchown(destfd, uid, gid);
-		fchflags(destfd, st.st_flags);
+		if (fchown(destfd, uid, gid) != 0)
+			warn("chown(%s)", p);
+		if (fchflags(destfd, st.st_flags) != 0)
+			warn("chflags(%s)", p);
 		close(destfd);
 	}
 	closedir(d);
diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c
index 8a9a4342f5ef..9f5cfb0f4473 100644
--- a/usr.sbin/pw/pw_user.c
+++ b/usr.sbin/pw/pw_user.c
@@ -123,7 +123,8 @@ mkdir_home_parents(int dfd, const char *dir)
 	if (fstatat(dfd, dirs, &st, 0) == -1) {
 		if (mkdirat(dfd, dirs, _DEF_DIRMODE) == -1)
 			err(EX_OSFILE,  "'%s' (home parent) is not a directory", dirs);
-		fchownat(dfd, dirs, 0, 0, 0);
+		if (fchownat(dfd, dirs, 0, 0, 0) != 0)
+			warn("chown(%s)", dirs);
 	}
 
 	free(dirs);