WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: No inotify events from TC Linux?  (Read 3939 times)

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
No inotify events from TC Linux?
« on: September 24, 2010, 03:13:38 PM »
Hello.  I'm working on developing an FLTK-native file manager.  I thought I could use the inotify API (http://linux.die.net/man/7/inotify) to provide feedback to my app whenever directory contents change, so I can automatically update the display. 

I tried it, and the API calls all seem to succeed, but I don't get any inotify events after creating or deleting files.  I set up the inotify watch on a particular directory (the dir file itself, not each of the contained files) and included watch options like IN_MODIFY.  I admit to just learning about this API, so it's possible I am still doing something wrong, but I wonder if TC's kernel is set up to provide inotify filesystem monitoring?

If not, it's not a big deal.  I can write my own monitoring routine, but mine will probably consume more CPU and be a little bit less power-friendly.  If any of the Core team knows about this API or how kernel config options affect it, I would appreciate hearing about it.  Thanks!
--
Mike Lockmoore

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: No inotify events from TC Linux?
« Reply #1 on: September 25, 2010, 02:22:40 AM »
Quote
CONFIG_FSNOTIFY=y
CONFIG_DNOTIFY=y
CONFIG_INOTIFY=y
CONFIG_INOTIFY_USER=y

It's also worked fine for me and Robert (the daemon for TC < 2.7). Checking the man page:

Quote
IN_CREATE         File/directory  created in watched directory (*).
           IN_DELETE         File/directory  deleted  from  watched  directory
                             (*).

Looks like you would need those too.
The only barriers that can stop you are the ones you create yourself.

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
Re: No inotify events from TC Linux?
« Reply #2 on: September 26, 2010, 11:45:54 AM »
@curaga: Thanks for replying.  EDIT: OK, that looks like the stock TC kernel should be configured for inotify.  The current kernel does not require a separate daemon running for other apps to receive the inotify events, does it?

When I tried the inotify API in my file manager C-program, I repeatedly checked for pending IO with an ioctl() call, and never saw any pending inotify info, even after deleting and creating files in the watched directory (and the parent directories, all the way up to /). Then, just for testing, I added  a blocking read() call on the file descriptor returned by the inotify initialize function.  That continued to block even after I deleted and created files in an external shell process. It's acting like either it's not really watching what I intended, or it is, but the kernel isn't providing the event info to the inotify API special file.

I'd like my app to work directly with TC Base.  Perhaps if my app needs a separate daemon inotify daemon running, it could be made a dependency if it not too big and difficult to manage.  Are either the libnotify or flnotify extensions related to this inotify stuff?
--
Mike L
« Last Edit: September 26, 2010, 12:23:34 PM by MikeLockmoore »

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: No inotify events from TC Linux?
« Reply #3 on: September 26, 2010, 12:46:59 PM »
I found that I had not posted the source to tce-notify, a small utility that I wrote for Tiny Core 2.7.
Quote
In TC/MC prior to v2.7, (2.0 - 2.6.1), a support extension, tce-notify, will be required. It should be loaded first, as only extensions loaded after it can benefit from its handling. This is a stopgap measure; upgrading to v2.7 is strongly recommended. tce-notify is a daemon which runs both ldconfig and depmod for every extension, so using it will put additional load on the system compared to the previous behavior.

Perhaps you will find the source useful:
http://distro.ibiblio.org/pub/linux/distributions/tinycorelinux/2.x/tce/src/tce-notify.c
10+ Years Contributing to Linux Open Source Projects.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: No inotify events from TC Linux?
« Reply #4 on: September 26, 2010, 01:16:06 PM »
Hm, I forgot tce-notify was using DNOTIFY and not INOTIFY. Attaching some sample code I made a year ago, it works ok on TC 3.
The only barriers that can stop you are the ones you create yourself.

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
Re: No inotify events from TC Linux?
« Reply #5 on: September 27, 2010, 09:11:12 AM »
@curaga, roberts:  Thanks for the code samples.  I will review and see if I can use these techniques in my app.

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
Re: No inotify events from TC Linux?
« Reply #6 on: September 27, 2010, 03:09:51 PM »
@curaga: 
Quote
... IN_CREATE ... IN_DELETE... Looks like you would need those too.

Yes, you are absolutely correct.  I wrongly assumed that any file creation and deletion operations would trigger a MODIFY event on the parent directory, but it appears that inotify does not work this way.  Adding the IN_CREATE and IN_DELETE flags on the watch request makes it work as I expect.  My full watch mask includes:

Code: [Select]
IN_ATTRIB | IN_MODIFY | IN_CREATE | IN_DELETE | IN_DELETE_SELF | IN_MOVE_SELF | IN_MOVE_TO | IN_MOVE_FROM | IN_MOVE_TO
Now in my app I just need to keep to keep the following things synchronized:
1) The actual filesystem state
2) The internal representation of a filesystem (which is normally a subset of #1)
3) The GUI presentation of the filesystem (which is normally a view of a subset of #2)

 ;)


Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: No inotify events from TC Linux?
« Reply #7 on: September 28, 2010, 08:22:45 AM »
Your mask has IN_MOVE_TO twice ;)
The only barriers that can stop you are the ones you create yourself.

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
Re: No inotify events from TC Linux?
« Reply #8 on: September 28, 2010, 11:40:59 PM »
@curaga: Copy+Paste error!   :-[

I have my app responding to external filesystem changes now using inotify.  At first, I tried to by fancy and keep removing and adding (or re-adding) inotify watches on only the currently-expanded parts of the directory tree (the parts you could see in the GUI).  But in this case, the inotify event info seemed to always refer back to a previous instance of a watch.  For example, at some point I have /tmp being watched.  Then the user changes something in the directory tree, so my app would use the inotify "remove watch" API call, then add it back again, which provided a new "watch descriptor".  However, when an external directory change happened, my app would get an event notification with the previous (removed!  >:() watch descriptor number. This was kind of inconvenient, since my code could no longer match this event to part of the filesystem.  I wonder if this is a kernel bug.  It seems kind of broken.   ??? Or perhaps I need to know how to flush any pending watch changes more immediately.

As a compromise, I don't remove watches now for the directories that are collapsed (i.e. no longer visible), and don't re-add ones already added.  So my app gets a few more potential updates than I need given the visible content, but that not too bad.  Hopefully, the total number of watches has a reasonable limit that most users won't hit.
--
Mike L.