Subject: bug#79433: 9.7: cp(1): lchownat(2/3) fallback bogus?

From: Steffen Nurpmeso <[email-masked]>
Date: Thu, 18 Sep 2025 16:36:57 +0200

Steffen Nurpmeso wrote in
 <20250918125710.WAELlo5o@steffen%sdaoden.eu>:

Sigh.
That build system is bogus anyhow, the manual pages are all
rebuild when i change a C source file?

  ...
 ||>    #?0|kent:tmp$ /bin/cp -a xb xc
 ||>    cp: failed to preserve ownership for xc: Operation not supported
 ...
 |I also disagree with "practical platforms" given that the
 |effective log difference seems to be (from a diff(1) glance)
 |
 |  +#define CHOWN_CHANGE_TIME_BUG 1
 |  +#define MKNOD_FIFO_BUG 1
 ...
 |All in all the [.] above [.] difference should not \
 |result in
 |a disfunctional cp(1) i would think.

I think i would possibly simply discard the return value of the
l?chmod() that is used in the fallback path.  The statement

          so we are required to update ctime.  Since lchown succeeded,
          we assume that lchmod will do likewise.  But if the system
          lacks lchmod and lutimes, we are out of luck.  Oh well.  */

seems a bit wacky given that there is NFS and fuse and maybe more,
and then this is inherently racy at first, and then updating the
ctime is not as "system-critical" as is the operation itself,
changing the owner, and that has already succeeded.  Thus i'd say

--- coreutils-9.7.old/lib/chown.c	2025-01-01 10:32:29.000000000 +0100
+++ coreutils-9.7/lib/chown.c	2025-09-18 16:32:00.535172071 +0200
@@ -130,7 +130,7 @@ rpl_chown (const char *file, uid_t uid,
          we assume that chmod will do likewise.  Fortunately, on all
          known systems where a 'no-op' chown skips the ctime update, a
          'no-op' chmod still does the trick.  */
-      result = chmod (file, st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO
+      /*result =*/ chmod (file, st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO
                                           | S_ISUID | S_ISGID | S_ISVTX));
     }
 # endif
--- coreutils-9.7.old/lib/lchown.c	2025-01-01 10:32:29.000000000 +0100
+++ coreutils-9.7/lib/lchown.c	2025-09-18 16:32:03.335172023 +0200
@@ -105,7 +105,7 @@ rpl_lchown (const char *file, uid_t uid,
          so we are required to update ctime.  Since lchown succeeded,
          we assume that lchmod will do likewise.  But if the system
          lacks lchmod and lutimes, we are out of luck.  Oh well.  */
-      result = lchmod (file, st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO
+      /*result =*/ lchmod (file, st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO
                                            | S_ISUID | S_ISGID | S_ISVTX));
     }
 # endif

Greetings,

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)