configure: detect fdopendir and a working dirfd()

The 3.5.0 directory-scan confinement opens directories with the secure
resolver and turns the held fd into a DIR* via fdopendir(), so detect
fdopendir.  dirfd() is a macro or static inline on several systems (the
BSDs), where the default AC_CHECK_FUNCS link probe gives a false
negative; probe it with a real compile+link that includes <dirent.h> and
calls it, so HAVE_DIRFD is defined and the confinement is not silently
compiled out.
This commit is contained in:
Andrew Tridgell committed 2026-06-12 16:19:13 +10:00
1 parent cd61c1cc62
commit ac82ccec8f
1 file changed
+13 -1
+13 -1
View File
@@ -908,7 +908,7 @@ dnl AC_FUNC_MEMCMP
AC_FUNC_UTIME_NULL
AC_FUNC_ALLOCA
AC_CHECK_FUNCS(waitpid wait4 getcwd chown chmod lchmod mknod mkfifo \
AC_CHECK_FUNCS(waitpid wait4 getcwd chown chmod lchmod mknod mkfifo fdopendir \
fchmod fstat ftruncate strchr readlink link utime utimes lutimes strftime \
chflags getattrlist mktime innetgr linkat mknodat mkfifoat \
memmove lchown vsnprintf snprintf vasprintf asprintf setsid strpbrk \
@@ -919,6 +919,18 @@ AC_CHECK_FUNCS(waitpid wait4 getcwd chown chmod lchmod mknod mkfifo \
initgroups utimensat posix_fallocate attropen setvbuf nanosleep usleep \
setenv unsetenv)
dnl dirfd() is a macro or static inline on several systems (the BSDs), so the
dnl default AC_CHECK_FUNCS link probe -- which declares `char dirfd(void);` and
dnl links against a bare symbol -- gives a false negative there. Probe it with a
dnl real compile+link that includes <dirent.h> and actually calls dirfd().
AC_CACHE_CHECK([for dirfd], rsync_cv_HAVE_DIRFD,
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <dirent.h>]],
[[DIR *d = opendir("."); return d ? dirfd(d) < -1 : 0;]])],
[rsync_cv_HAVE_DIRFD=yes], [rsync_cv_HAVE_DIRFD=no])])
if test x"$rsync_cv_HAVE_DIRFD" = x"yes"; then
AC_DEFINE([HAVE_DIRFD], 1, [Define to 1 if you have a working dirfd() (function or macro).])
fi
dnl cygwin iconv.h defines iconv_open as libiconv_open
if test x"$ac_cv_func_iconv_open" != x"yes"; then
AC_CHECK_FUNC(libiconv_open, [ac_cv_func_iconv_open=yes; AC_DEFINE(HAVE_ICONV_OPEN, 1)])