From 71e56488132021d0b67970c70278c13e5b2c2e26 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Tue, 10 Oct 2023 23:48:52 +0800 Subject: [PATCH] Fix detection of statx.stx_mnt_id on buggy glibc * https://gitlab.haskell.org/ghc/ghc/-/issues/24072 * https://lore.kernel.org/all/20220223111835.00ef0e83@bahia/T/ --- System/Posix/Files/Common.hsc | 6 +++--- changelog.md | 1 + configure.ac | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/System/Posix/Files/Common.hsc b/System/Posix/Files/Common.hsc index c0cd6b6..1f44f7d 100644 --- a/System/Posix/Files/Common.hsc +++ b/System/Posix/Files/Common.hsc @@ -940,7 +940,7 @@ pattern StatxBtime = StatxMask 0 -- | Want @stx_mnt_id@. pattern StatxMntId :: StatxMask -#ifdef STATX_MNT_ID +#ifdef HAVE_STATX_MNT_ID pattern StatxMntId = StatxMask (#const STATX_MNT_ID) #else pattern StatxMntId = StatxMask 0 @@ -1160,11 +1160,11 @@ specialDeviceIDX (ExtendedFileStatus statx) = unsafePerformIO $ do {-# WARNING specialDeviceIDX "specialDeviceIDX: not available on this platform, will throw error (CPP guard: @#if HAVE_SYS_SYSMACROS_H@)" #-} specialDeviceIDX _ = error "specialDeviceIDX not available on this platform" #endif -#ifdef STATX_MNT_ID +#ifdef HAVE_STATX_MNT_ID mountIDX (ExtendedFileStatus statx) = unsafePerformIO $ withForeignPtr statx $ (#peek struct statx, stx_mnt_id) #else -{-# WARNING mountIDX "mountIDX: not available on this platform, will throw error (CPP guard: @#if STATX_MNT_ID@)" #-} +{-# WARNING mountIDX "mountIDX: not available on this platform, will throw error (CPP guard: @#if HAVE_STATX_MNT_ID@)" #-} mountIDX _ = error "mountIDX not available on this platform" #endif fileBlockSizeX (ExtendedFileStatus statx) = unsafePerformIO $ do diff --git a/changelog.md b/changelog.md index 5318270..2f3fdb2 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ ## 2.8.4.0 *??? 2023* * add `haveStatx` + * fix `statx.stx_mnt_id` detection on buggy glibc, see [GHC #24072](https://gitlab.haskell.org/ghc/ghc/-/issues/24072) ## 2.8.3.0 *Oct 2023* diff --git a/configure.ac b/configure.ac index 978b7ad..2f36f52 100644 --- a/configure.ac +++ b/configure.ac @@ -50,6 +50,23 @@ AC_CHECK_TYPE([struct rlimit],[AC_DEFINE([HAVE_STRUCT_RLIMIT],[1],[HAVE_STRUCT_R # check for statx AC_CHECK_FUNC([statx], [AC_DEFINE([HAVE_STATX_FUN],[1],[HAVE_STATX_FUN])],[],[#include ]) AC_CHECK_TYPE([struct statx],[AC_DEFINE([HAVE_STRUCT_STATX],[1],[HAVE_STRUCT_STATX])],[],[#include ]) +AC_MSG_CHECKING(for statx.stx_mnt_id) +AC_LINK_IFELSE([ +AC_LANG_PROGRAM([[#include ]], +[[ +struct statx statxbuf; +statx(0, "", 0, STATX_BASIC_STATS | STATX_MNT_ID, &statxbuf); +return statxbuf.stx_mnt_id; +]])], +[ +AC_MSG_RESULT(yes) +AC_DEFINE([HAVE_STATX_MNT_ID], [1], [Define to 1 if statx.stx_mnt_id is available.]) +], +[ +AC_MSG_RESULT(no) +] +) + AC_MSG_CHECKING(for F_GETLK from fcntl.h) AC_EGREP_CPP(yes,