tinkershack/fluffy

fluffy is watching at its own event logging files

frzb opened this issue · 5 comments

frzb commented

fluffy is the only software that I know that can handle recursive Inotfiy file system event watches properly.
Well done!
Well, something is a little bit odd when writing STDOUT and STDERR to output files.

Observed behaviour

fluffly is always watching implicitly on its own logfiles always leaving some unwanted traces in the files.
Even if you try to to exclude the path of the output files form the file watches as fast a possible.

Assuming this tiny script to run fluffy:

#!/bin/bash

sudo fluffy -O /opt/fluffy/fluffy.log -E /opt/fluffy/fluffy.log &

sudo fluffyctl -w /opt -i /opt/fluffy 

sudo touch /opt/ready

Result

This results in the following output file: /opt/fluffy/fluffy.log

MODIFY, /opt/fluffy/fluffy.log
ACCESS,ISDIR,   /opt
MODIFY, /opt/fluffy/fluffy.log
CLOSE_NOWRITE,ISDIR,    /opt
MODIFY, /opt/fluffy/fluffy.log
IGNORED,        /opt/fluffy
CREATE, /opt/ready
OPEN,   /opt/ready
ATTRIB, /opt/ready
CLOSE_WRITE,    /opt/ready

Touching the file /opt/ready is done when the script above is done.

Expected behavior

fluffy should ignore file system events for its own output files at all.
For my understanding it does not make any sense to recognize them.

The whole situation also gets worse if one forgets to exclude the path where the output files are written from watching.
Then fluffy ends in some kind of infinite loop because accessing and writing to the files creates events which are logged to file and so on.

fluffy is the only software that I know that can handle recursive Inotfiy file system event watches properly.
Well done!

Thank you. Happy to help!

fluffy should ignore file system events for its own output files at all.

Agreed. I seem to have overlooked this. Thanks for reporting!

Patched. Please give it a go and confirm the fix?

Now that I recall, it was deliberately left that way.

A good fix should have been just an update to the output flag description clearly stating not to provide a log path which is nested within a watch directory(root watch path).

Fluffy sets watches on directories, not files. So, we will be able to remove only those watches that were set. Then, of course Fluffy won't be able to remove the watch on log files that was never set in the first place. Nevertheless, we can choose to ignore logging the events that occur on the log file itself which were caught by the log files' parent directory. This is what the referenced patch does. This becomes terribly inefficient when the root watch paths contain deeply nested directory structures with a rather large number of entries. Shortly put, we loose efficiency by filling up the inotify queue at an alarmingly faster rate. Even though our event consumption from the inotify event queue is multi threaded, we may be unnecessarily burdening ourselves with additional compute!

I'm sorry for not fixing this. This may be an inconvenience, not a bug though. I'll retract the patch and update the flag description appropriately.

@frzb Please feel free to re-open this issue if you would like to suggest or discuss more.

frzb commented

Thank you for your efforts.
I am currently tinkering around and will come back to you when the experience I collect make it possible to make an conclusion.