The renameatu and rename tests fail on GNU/Hurd since renameat2 on that platform does not properly handle trailing slashes. I've reported that bug with a test case [1].
Applied the attached patch which adds a configure check and documents the bug. [1] https://sourceware.org/bugzilla/show_bug.cgi?id=32570
>From 1e3de03067bf1ca2cec2dc2ce64f682bcf66b5d9 Mon Sep 17 00:00:00 2001 From: Collin Funk <collin.fu...@gmail.com> Date: Sat, 18 Jan 2025 21:06:49 -0800 Subject: [PATCH] renameatu: Work around a GNU/Hurd bug. * m4/renameat.m4 (gl_FUNC_RENAMEAT): Check if renameat2 handles trailing slashes. * doc/glibc-functions/renameat2.texi: Mention the GNU/Hurd bug. --- ChangeLog | 5 +++++ doc/glibc-functions/renameat2.texi | 6 ++++++ m4/renameat.m4 | 13 +++++++++++++ 3 files changed, 24 insertions(+) diff --git a/ChangeLog b/ChangeLog index 2057a6da9a..283f98849d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2025-01-18 Collin Funk <collin.fu...@gmail.com> + renameatu: Work around a GNU/Hurd bug. + * m4/renameat.m4 (gl_FUNC_RENAMEAT): Check if renameat2 handles trailing + slashes. + * doc/glibc-functions/renameat2.texi: Mention the GNU/Hurd bug. + linkat tests: Revert the last change. * tests/test-linkat.c (main): Disallow EINVAL an alternative error value. diff --git a/doc/glibc-functions/renameat2.texi b/doc/glibc-functions/renameat2.texi index d3f8c4e8a3..5f281ee0a3 100644 --- a/doc/glibc-functions/renameat2.texi +++ b/doc/glibc-functions/renameat2.texi @@ -19,6 +19,12 @@ @node renameat2 This function succeeds when the @code{RENAME_NOREPLACE} flag is specified and the source and destination are the same file, on some platforms: Cygwin 3.4.6. +@item +@code{renameat2 (AT_FDCWD, "file", AT_FDCWD, "new/" ...)} succeeds +instead of failing and setting @code{errno} to @code{ENOTDIR}, on some +platforms: +@c https://sourceware.org/bugzilla/show_bug.cgi?id=32570 +GNU/Hurd. @end itemize @mindex renameatu diff --git a/m4/renameat.m4 b/m4/renameat.m4 index f967ae1593..238412d728 100644 --- a/m4/renameat.m4 +++ b/m4/renameat.m4 @@ -31,14 +31,24 @@ AC_DEFUN([gl_FUNC_RENAMEAT] [gl_cv_func_renameat2_works], [AC_RUN_IFELSE( [AC_LANG_SOURCE([[ + #include <unistd.h> #include <fcntl.h> #include <stdio.h> int main () { + int fd; /* This test fails on Cygwin 3.4.6. */ if (renameat2 (AT_FDCWD, "conftest.c", AT_FDCWD, "conftest.c", RENAME_NOREPLACE) == 0) return 1; + fd = open ("conftest.a", O_CREAT | O_EXCL | O_WRONLY, 0600); + if (fd < 0) + return 1; + /* This test fails on GNU/Hurd. */ + if (renameat2 (AT_FDCWD, "conftest.a", AT_FDCWD, "conftest.b/", 0) == 0) + return 1; + if (close (fd) < 0) + return 1; return 0; } ]])], @@ -47,12 +57,15 @@ AC_DEFUN([gl_FUNC_RENAMEAT] [case "$host_os" in # Guess yes on Linux. linux*) gl_cv_func_renameat2_works="guessing yes" ;; + # Guess no on GNU/Hurd. + gnu*) gl_cv_func_renameat2_works="guessing no" ;; # Guess no on Cygwin. cygwin*) gl_cv_func_renameat2_works="guessing no" ;; # If we don't know, obey --enable-cross-guesses. *) gl_cv_func_renameat2_works="$gl_cross_guess_normal" ;; esac ]) + rm -rf conftest.a conftest.b ]) case "$gl_cv_func_renameat2_works" in *yes) -- 2.48.1