Re: How to monitor a directory in FreeBSD?

From: Michał_Górny <mgorny_at_moritz.systems>
Date: Sat, 13 Aug 2022 19:19:16 UTC
On Sat, 2022-08-13 at 21:09 +0200, meator wrote:
> On 8/13/22 17:35, Gleb Popov wrote:
> > 
> > Yes, there is no native API to monitor directories. You can use 
> > libinotify from ports, which replicates Linux inotify API and it does 
> > have ability to monitor directories.
> > 
> 
> I would like to avoid extra dependencies. If I would like to do this, 
> than I would probably choose FAM of Gamin. The Linux Programming 
> Interface book references these two as a more cross platform 
> alternatives to inotify. The program I'm working on should also work on 
> Linux. I'm currently want to implement both inotify and kqueue and make 
> the preprocessor pick the right one when compiling.
> 
> But I didn't know inotify for BSD exists. This would mean that I 
> wouldn't have to implement the directory monitoring twice. I'll take 
> this into consideration. Thanks!

I'm afraid I'm going to be a bit of spoilsport but please bear in mind
that inotify -- at least on Linux -- is not 100% reliable (or at least
it wasn't the last time I've used it).  In general, it's a great
optimization but your program also needs to have fallback logic to
periodically check for changes that weren't reported.

-- 
Best regards,
Michał Górny