[PATCH v4 01/24] freebsd: FreeBSD 15 has native inotify

Warner Losh posted 24 patches 1 month, 2 weeks ago
Maintainers: Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Riku Voipio <riku.voipio@iki.fi>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
[PATCH v4 01/24] freebsd: FreeBSD 15 has native inotify
Posted by Warner Losh 1 month, 2 weeks ago
Check to make sure that we have inotify in libc, before looking for it
in libinotify.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Daniel P. Berrange <berrange@redhat.com>
Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 meson.build      | 14 +++++---------
 util/meson.build |  6 +-----
 2 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/meson.build b/meson.build
index 4af32c3e1f..3d761f89b5 100644
--- a/meson.build
+++ b/meson.build
@@ -2664,18 +2664,14 @@ else
 endif
 config_host_data.set('CONFIG_ASAN_IFACE_FIBER', have_asan_fiber)
 
+inotify = not_found
 have_inotify_init = cc.has_header_symbol('sys/inotify.h', 'inotify_init')
 have_inotify_init1 = cc.has_header_symbol('sys/inotify.h', 'inotify_init1')
-inotify = not_found
-if (have_inotify_init or have_inotify_init1) and host_os == 'freebsd'
-  # libinotify-kqueue
+if (have_inotify_init or have_inotify_init1) and not cc.has_function('inotify_init1')
+  # FreeBSD 14 and older need libinotify-kqueue wrapper
   inotify = cc.find_library('inotify')
-  if have_inotify_init
-    have_inotify_init = inotify.found()
-  endif
-  if have_inotify_init1
-    have_inotify_init1 = inotify.found()
-  endif
+  have_inotify_init = have_inotify_init and inotify.found()
+  have_inotify_init1 = have_inotify_init1 and inotify.found()
 endif
 config_host_data.set('CONFIG_INOTIFY', have_inotify_init)
 config_host_data.set('CONFIG_INOTIFY1', have_inotify_init1)
diff --git a/util/meson.build b/util/meson.build
index 7c9445615d..e7a2a2a64c 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -102,11 +102,7 @@ if have_block
   util_ss.add(files('throttle.c'))
   util_ss.add(files('timed-average.c'))
   if config_host_data.get('CONFIG_INOTIFY1')
-    freebsd_dep = []
-    if host_os == 'freebsd'
-      freebsd_dep = inotify
-    endif
-    util_ss.add(files('filemonitor-inotify.c'), freebsd_dep)
+    util_ss.add(files('filemonitor-inotify.c'), inotify)
   else
     util_ss.add(files('filemonitor-stub.c'))
   endif

-- 
2.52.0


Re: [PATCH v4 01/24] freebsd: FreeBSD 15 has native inotify
Posted by Michael Tokarev 1 month ago
On 24.02.2026 17:40, Warner Losh wrote:
> Check to make sure that we have inotify in libc, before looking for it
> in libinotify.
> 
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
> Cc: Daniel P. Berrange <berrange@redhat.com>
> Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>   meson.build      | 14 +++++---------
>   util/meson.build |  6 +-----
>   2 files changed, 6 insertions(+), 14 deletions(-)
> 
> diff --git a/meson.build b/meson.build
> index 4af32c3e1f..3d761f89b5 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -2664,18 +2664,14 @@ else
>   endif
>   config_host_data.set('CONFIG_ASAN_IFACE_FIBER', have_asan_fiber)
>   
> +inotify = not_found
>   have_inotify_init = cc.has_header_symbol('sys/inotify.h', 'inotify_init')
>   have_inotify_init1 = cc.has_header_symbol('sys/inotify.h', 'inotify_init1')
> -inotify = not_found
> -if (have_inotify_init or have_inotify_init1) and host_os == 'freebsd'
> -  # libinotify-kqueue
> +if (have_inotify_init or have_inotify_init1) and not cc.has_function('inotify_init1')
> +  # FreeBSD 14 and older need libinotify-kqueue wrapper
>     inotify = cc.find_library('inotify')
> -  if have_inotify_init
> -    have_inotify_init = inotify.found()
> -  endif
> -  if have_inotify_init1
> -    have_inotify_init1 = inotify.found()
> -  endif
> +  have_inotify_init = have_inotify_init and inotify.found()
> +  have_inotify_init1 = have_inotify_init1 and inotify.found()
>   endif
>   config_host_data.set('CONFIG_INOTIFY', have_inotify_init)
>   config_host_data.set('CONFIG_INOTIFY1', have_inotify_init1)

Does freebsd have inotify_init() or inotify_init1() or both?

I sent another patch for this area, which drops checking for
the original/early inotify_init(), because this function is
actually not used in qemu, - qemu only uses the more modern
inotify_init1() interface.

Now my change clashes with this change in a fun way.

Do we really need to check for inotify_init() at all?

Thanks,

/mjt

Re: [PATCH v4 01/24] freebsd: FreeBSD 15 has native inotify
Posted by Gleb Popov 1 month, 2 weeks ago
On Tue, Feb 24, 2026 at 5:41 PM Warner Losh <imp@bsdimp.com> wrote:
>
> Check to make sure that we have inotify in libc, before looking for it
> in libinotify.

This is how I solved the same problem in KDE lands (which uses CMake) [1].
In short, the algorithm is following:
1. Call into pkg-config to see if there is a .pc module for inotify
2. Check if /usr/include/sys/inotify.h exists
3. If there is no pkg-config module and no header -> no inotify
4. If there is no pkg-config module, but the header exists -> we have
"native" inotify,
    no CFLAGS/LDFLAGS manipulation needed
5. If there is pkg-config module, but no header -> use CFLAGS/LDFLAGS from
    pkg-config (IIRC, this is handled by the "dependency" function in
Meson). This
    case happens on FreeBSD where system and 3rd party headers are separated
    (/usr/include vs. /usr/local/include)
6. If we have both pkg-config module and /usr/include/sys/inotify.h,
then we need
    to figure if this header corresponds to libinotify-kqueue, or it
is a native one.
    This is done by comparing the installation prefix of the library and "/usr".

Hope that helps.

[1] https://invent.kde.org/frameworks/extra-cmake-modules/-/merge_requests/566