inotify - IN_DELETE_SELF
Hi @ all!
First, i try du keep up of additions to my music directory; so i take the the basedir, add a watch, scan it for directories, add a watch for a hit - looping in that procedure.
Each watch its descriptor i take as a key in an array of *char to save the directories absolute path.
I asume an IN_DELETE_SELF event would me give back the watch descriptor i need to dealloc the stringspace i saved the absolut path in.
I cannot work with the IN_DELETE event, because it gives me the watch descriptor of the directory in which the deletion occurs.
But...i do not get the IN_DELETE_SELF event!? - please, what do you think...why?
Hmmm inotify is fun, let me dig into this after my chores for the day are done. To be clear, are you trying to watch for a directory being deleted (so you can clean up internal memory associated with it)?
Originally Posted by jeffcobb
I watch the directories for actions; the happenings therein will be notified, and i get the name of the file/directory which the event produced in the member 'name' of the struct 'event' inotify posts.
If a file is created, i purpose to multicast on dbus to start the applet for completion of the mp3 tags. That is no trouble to me.
If a directory is created, i add a watch, get back the unique watchdescriptor (integer), and that indexes a *char [ 65536 ] (hey, maybe someone knows me a symbol for the max. integer value!?) where i save a pointer to the stringspace i placed the absolute path into. It seems pretty handy so far.
What i need is the <watch descriptor> the deleted directory itself watching for the index , to free the stringspace i got with malloc.
But, i do not get the IN_DELETE_SELF event, for my understanding he should work that way.
I don't know anything about inotify, but 65536 is not a normal int max -- it would be, for an unsigned two byte int (the "short int"). The max value of an unsigned variable is not the same as the max value of a signed variable twice it's size, if that is the logic you were using.
Originally Posted by nynhjan
Anyway, the best thing there is to #include <limits.h> and use the INT_MAX macro. On most systems that is 2147483647.
...oh thanks! - thats what i thought about.
Originally Posted by MK27
Now, that i tried it (hopefully i do not blast the thread), something faulty: size of array is too large.
Could load the possible amount of watchdescriptors from /proc/sys/fs/inotify/max_user_watches ... now, nice would it be if i could define a macro to read out that value AND is usable in a struct definition. *rofl* - possible?
...it also seems not to matter if it is a file that is deleted, or the watch is deleted by the function inotify_rm_watch inside the program - i never get IN_DELETE_SELF.
Chores almost done, will be at this soon...
OK do you know the difference between IN_DELETE and IN_DELETE_SELF? I have IN_DELETE working fine and can supply a demo but maybe its not what you are looking for....this is based on some code samples from Robert Love I think (kernel hacker) ....
Actually I just looked it up but not really seeing a situation where IN_DELETE_SELF would work and IN_DELETE would not...
Or it looks like you could watch for IN_ALL_EVENTS, trigger your target condition and see what gets reported...