]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: ifdef for fanotify support on older systems
authorKarel Zak <kzak@redhat.com>
Thu, 7 Aug 2025 11:15:32 +0000 (13:15 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 7 Aug 2025 11:18:31 +0000 (13:18 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
configure.ac
libmount/src/monitor_fanotify.c
libmount/src/version.c
meson.build

index f076f60f10ce5a2f5935eef3553203e2a84bb610..6836f0564aab73652fff7b9cff308663df7664ee 100644 (file)
@@ -550,6 +550,8 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 [AC_DEFINE([HAVE_TM_GMTOFF], [1], [Does struct tm have a field tm_gmtoff?])
 ])
 
+AC_CHECK_TYPES([struct fanotify_event_info_header], [], [], [[#include <linux/fanotify.h>]])
+
 AC_CHECK_TYPES([struct mount_attr], [], [], [[#include <linux/mount.h>]])
 AC_CHECK_TYPES([enum fsconfig_command], [], [], [[#include <linux/mount.h>]])
 
index 7e6903bebd5a018df07fe4e23e521581fcb30a08..e9e6e64f6648a5489408b89a84229aec5dd5d01a 100644 (file)
 #include "mountP.h"
 #include "monitor.h"
 
+/*
+ * The fanotify info header is suppported since kernel v5.1 (commit 5e469c830fdb5).
+ *
+ * We do not provide fallback for so old systems. There is fallback only for
+ * missing "struct fanotify_event_info_mnt" (since v6.15, commit 0f46d81f2bce9).
+ */
+#ifdef HAVE_STRUCT_FANOTIFY_EVENT_INFO_HEADER
+
 #include "strutils.h"
 #include "pathnames.h"
 
@@ -319,3 +327,16 @@ err:
        DBG(MONITOR, ul_debugobj(mn, "failed to allocate fanotify monitor [rc=%d]", rc));
        return rc;
 }
+
+
+#else /* !HAVE_STRUCT_FANOTIFY_EVENT_INFO_HEADER */
+
+int mnt_monitor_enable_fanotify(
+               struct libmnt_monitor *mn __attribute__((__unused__)),
+               int enable __attribute__((__unused__)),
+               int ns __attribute__((__unused__)))
+{
+       errno = ENOTSUP;
+       return -errno;
+}
+#endif
index 3b61618b5530d867bc28919ead8743f16f5b2836..19326d280cb2ec2406e917ec3f77c950278cc31a 100644 (file)
@@ -49,6 +49,9 @@ static const char *lib_features[] = {
 #if defined(HAVE_STATX) && defined(HAVE_STRUCT_STATX) && defined(AT_STATX_DONT_SYNC)
        "statx",
 #endif
+#ifdef HAVE_STRUCT_FANOTIFY_EVENT_INFO_HEADER
+       "fanotify",
+#endif
 #if !defined(NDEBUG)
        "assert",       /* libc assert.h stuff */
 #endif
index 68c040442d166f29fcaf8d8688d14b7d10c0d032..e3038240a8258ff846b635e6126e2570cc948c02 100644 (file)
@@ -99,11 +99,13 @@ login_lastlogin = get_option('login-lastlogin')
 conf.set('USE_LOGIN_LASTLOG', login_lastlogin ? 1 : false)
 summary('login-lastlogin', login_lastlogin ? 'enabled' : 'disabled', section : 'components')
 
+have = cc.has_type('struct fanotify_event_info_header', prefix : '#include <linux/fanotify.h>')
+conf.set('HAVE_STRUCT_FANOTIFY_EVENT_INFO_HEADER', have ? 1 : false)
+
 have_mountfd_api = cc.has_type('struct mount_attr', prefix : '#include <linux/mount.h>')
 conf.set('HAVE_STRUCT_MOUNT_ATTR', have_mountfd_api ? 1 : false)
 conf.set('HAVE_MOUNTFD_API', have_mountfd_api ? 1 : false)
 
-
 have_struct_statx = cc.has_type('struct statx', prefix : '#include <sys/stat.h>')
 conf.set('HAVE_STRUCT_STATX', have_struct_statx ? 1 : false)
 have = cc.has_member('struct statx', 'stx_mnt_id',