Detect when a file has been recreated using a stat watcher
schmorp at schmorp.de
Fri Dec 26 22:47:28 CET 2008
On Wed, Dec 24, 2008 at 12:40:46PM +0200, Graham Leggett <minfrin at sharp.fm> wrote:
> >I don't know, it depends entirely on how you define "logfile rotation",
> >which probably relies on whatever program does the actual rotation.
> As in the file gets deleted and/or truncated, and the event driven
> application watching the file gets notified by some mechanism that this
> has happened.
Well, the ctime would likely change in those cases, as well as (likely)
the inode number and (likely) the size, all of which could be detected via
a stat watcher.
> >We were talking about timestamp resolution, and what to do about
> >it. And this is cetrainly being explained in the docs.
> Er, no, I think you have misunderstood my question.
No, you completely midrepresent your e-mail, and that's no fun.
> I am not talking at all about timestamp resolution,
You *were* talking about stat time resolution.
> Both inotify and kqueue can (apparently) detect file deletion/renaming
Firts of all, no, they can't, at least not with certainty. This detection
only works on some filesystems for example.
> although it seems that libev does not (yet) expose these events
libev *caqnnot* expose these events as such because a) libev tries to be
reliable and b) libev is a portable library, and the only thing available
portably is stat.
libev is *not* a wrapper around inotify, it only *uses* inotify to
implement its (portable) stat watchers, and it only uses inotify as a hint
mechanism (and in this case it actually does check for file deletions).
So if you want to write an OS X only program, then you should be free to
use kqueue, similarly for gnu/linux, but it's not acceptable for libev to
become, say, a linux-only library.
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / pcg at goof.com
More information about the libev