Thread: inotify - IN_DELETE_SELF

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    4

    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?

  2. #2
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    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)?
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    4
    Quote Originally Posted by jeffcobb View Post
    clear, are you trying to watch for a directory being deleted (so you can clean up internal memory associated with it)?
    Yes.

    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.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by nynhjan View Post
    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!?)
    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.

    Anyway, the best thing there is to #include <limits.h> and use the INT_MAX macro. On most systems that is 2147483647.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    4
    Quote Originally Posted by MK27 View Post
    INT_MAX
    ...oh thanks! - thats what i thought about.

    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?

  6. #6
    Registered User
    Join Date
    Jan 2010
    Posts
    4
    ...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.

  7. #7
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Chores almost done, will be at this soon...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  8. #8
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    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) ....
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  9. #9
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Actually I just looked it up but not really seeing a situation where IN_DELETE_SELF would work and IN_DELETE would not...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  10. #10
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Or it looks like you could watch for IN_ALL_EVENTS, trigger your target condition and see what gets reported...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inotify problem
    By MisterIO in forum Linux Programming
    Replies: 17
    Last Post: 11-14-2008, 11:02 AM
  2. inotify woes
    By quixote in forum Linux Programming
    Replies: 6
    Last Post: 01-26-2008, 01:58 AM