Paul Eggert wrote: > + dnl Since the problem occurs only on OpenBSD, just test for that.
The problem occurs not only on OpenBSD, but also on Cygwin 2.9.0. (Newer Cygwin releases, such as 3.6.4, have it fixed.) So, in the current state, on Cygwin 2.9.0, there are 3 test failures: FAIL: test-chown ================ ../../gltests/test-chown.h:113: assertion 'st1.st_ctime < st2.st_ctime || (st1.st_ctime == st2.st_ctime && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2))' failed FAIL test-chown.exe (exit status: 134) FAIL: test-fchownat =================== ../../gltests/test-chown.h:113: assertion 'st1.st_ctime < st2.st_ctime || (st1.st_ctime == st2.st_ctime && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2))' failed FAIL test-fchownat.exe (exit status: 134) FAIL: test-lchown ================= ../../gltests/test-lchown.h:121: assertion 'st1.st_ctime < st2.st_ctime || (st1.st_ctime == st2.st_ctime && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2))' failed FAIL test-lchown.exe (exit status: 134) With the patch below, I'm fixing 2 of these failures; the remaining one being: FAIL: test-fchownat =================== ../../gltests/test-lchown.h:185: assertion 'st1.st_gid == st2.st_gid' failed FAIL test-fchownat.exe (exit status: 134) which is the same as seen on OpenBSD 7.6. The chances are high that when the test failure on OpenBSD 7.6 will have been fixed, the one on Cygwin 2.9.0 will be fixed as well. 2025-09-21 Bruno Haible <br...@clisp.org> chown, lchown: Fix regression on Cygwin 2.9.0 (regression today). * m4/chown.m4 (AC_FUNC_CHOWN): Restore the previous configure-time test on OpenBSD and Cygwin platforms. * doc/posix-functions/chown.texi: Update platforms list. diff --git a/doc/posix-functions/chown.texi b/doc/posix-functions/chown.texi index fb100efa04..17e305de25 100644 --- a/doc/posix-functions/chown.texi +++ b/doc/posix-functions/chown.texi @@ -16,7 +16,7 @@ @item Some platforms fail to update the change time when at least one argument was not @minus{}1, but no ownership changes resulted: -OpenBSD 7.7. +OpenBSD 7.7, Cygwin 2.9.0. @item When passed an argument of @minus{}1, some implementations really set the owner user/group id of the file to this value, rather than leaving that id of the diff --git a/m4/chown.m4 b/m4/chown.m4 index 37993cfa78..f899f3b680 100644 --- a/m4/chown.m4 +++ b/m4/chown.m4 @@ -1,5 +1,5 @@ # chown.m4 -# serial 38 +# serial 39 dnl Copyright (C) 1997-2001, 2003-2005, 2007, 2009-2025 Free Software dnl Foundation, Inc. dnl This file is free software; the Free Software Foundation @@ -133,13 +133,36 @@ AC_DEFUN_ONCE([gl_FUNC_CHOWN] dnl OpenBSD fails to update ctime if ownership does not change. AC_CACHE_CHECK([whether chown updates ctime per POSIX], [gl_cv_func_chown_ctime_works], - [dnl Although this formerly used AC_RUN_IFELSE, that was tricky - dnl as it depended on timing and file timestamp resolution, - dnl and there were false positives when configuring with Linux fakeroot. - dnl Since the problem occurs only on OpenBSD, just test for that. + [dnl This test is tricky as it depends on timing and file timestamp + dnl resolution, and there were false positives when configuring with + dnl Linux fakeroot. Since the problem occurs only on OpenBSD and Cygwin, + dnl test only on these platforms. AS_CASE([$host_os], - [openbsd*], [gl_cv_func_chown_ctime_works=no], - [gl_cv_func_chown_ctime_works=yes])]) + [openbsd* | cygwin*], + [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ +#include <unistd.h> +#include <stdlib.h> +#include <errno.h> +#include <fcntl.h> +#include <sys/stat.h> +]GL_MDA_DEFINES], + [[struct stat st1, st2; + if (close (creat ("conftest.file", 0600))) return 1; + if (stat ("conftest.file", &st1)) return 2; + sleep (1); + if (chown ("conftest.file", st1.st_uid, st1.st_gid)) return 3; + if (stat ("conftest.file", &st2)) return 4; + if (st2.st_ctime <= st1.st_ctime) return 5; + ]])], + [gl_cv_func_chown_ctime_works=yes], + [gl_cv_func_chown_ctime_works=no], + [# Obey --enable-cross-guesses. + gl_cv_func_chown_ctime_works="$gl_cross_guess_normal" + ]) + rm -f conftest.file + ], + [gl_cv_func_chown_ctime_works=yes]) + ]) case "$gl_cv_func_chown_ctime_works" in *yes) ;; *)