From: Karel Zak Date: Thu, 7 Aug 2025 11:15:32 +0000 (+0200) Subject: libmount: ifdef for fanotify support on older systems X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=489ebfe7046136ca02b6df7ec5b75f3daa2980fb;p=thirdparty%2Futil-linux.git libmount: ifdef for fanotify support on older systems Signed-off-by: Karel Zak --- diff --git a/configure.ac b/configure.ac index f076f60f1..6836f0564 100644 --- a/configure.ac +++ b/configure.ac @@ -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 ]]) + AC_CHECK_TYPES([struct mount_attr], [], [], [[#include ]]) AC_CHECK_TYPES([enum fsconfig_command], [], [], [[#include ]]) diff --git a/libmount/src/monitor_fanotify.c b/libmount/src/monitor_fanotify.c index 7e6903beb..e9e6e64f6 100644 --- a/libmount/src/monitor_fanotify.c +++ b/libmount/src/monitor_fanotify.c @@ -14,6 +14,14 @@ #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 diff --git a/libmount/src/version.c b/libmount/src/version.c index 3b61618b5..19326d280 100644 --- a/libmount/src/version.c +++ b/libmount/src/version.c @@ -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 diff --git a/meson.build b/meson.build index 68c040442..e3038240a 100644 --- a/meson.build +++ b/meson.build @@ -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 ') +conf.set('HAVE_STRUCT_FANOTIFY_EVENT_INFO_HEADER', have ? 1 : false) + have_mountfd_api = cc.has_type('struct mount_attr', prefix : '#include ') 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 ') conf.set('HAVE_STRUCT_STATX', have_struct_statx ? 1 : false) have = cc.has_member('struct statx', 'stx_mnt_id',