LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-09-2014, 08:40 AM   #1
rex1254
LQ Newbie
 
Registered: Aug 2014
Posts: 15

Rep: Reputation: Disabled
select method fails when IN_DELETE event of inotify occurs


I am trying to monitor a directory recursively on Linux using inotify. I am using select method in my application to monitor directory changes. I get notification for all the events except for delete. When ever i delete a directory, using rm command, my select method fails.

I get the following error "invalid or incomplete multibyte or wide character"

How can i solve this problem.

Thanks for the reply

fd = inotify_init();

struct timeval time;
fd_set rfds;
int ret;

/* timeout after five seconds */
time.tv_sec = 5;
time.tv_usec = 0;

/* zero-out the fd_set */
FD_ZERO (&rfds);

/*
* add the inotify fd to the fd_set -- of course,
* your application will probably want to add
* other file descriptors here, too
*/
FD_SET (fd, &rfds);

ret = select (fd + 1, &rfds, NULL, NULL, &time);
if (ret < 0)
perror ("select");
else if (!ret)
/* timed out! */
else if (FD_ISSET (fd, &rfds)
/* inotify events are available! */
{
// inotify events are available
len = read(fd, buf, EVENT_BUF_LEN);
if(len <= 0)
{
qDebug()<<"Error : read failed..";
perror("read : ");
}

while(i < len)
{
struct inotify_event *event;
event = (struct inotify_event *) &buf[i];

eventNotification(event);
i += EVENT_SIZE + event->len;
count++;
}
}

void eventNotification (struct inotify_event *event)
{
if ( event->len )
{
if ( event->mask & IN_CREATE )
{
if ( event->mask & IN_ISDIR )
{
printf( "The directory %s was created.\n", event->name );
}
else
{
printf( "The file %s was created.\n", event->name );
}
}
else if ( event->mask & IN_DELETE )
{
if ( event->mask & IN_ISDIR )
{
printf( "The directory %s was deleted.\n", event->name );
}
else
{
printf( "The file %s was deleted.\n", event->name );
}
}
else if ( event->mask & IN_MODIFY )
{
if ( event->mask & IN_ISDIR )
{
printf( "The directory %s was modified.\n", event->name );
}
else
{
printf( "The file %s was modified.\n", event->name );
}
}
}
}
 
Old 09-10-2014, 07:01 AM   #2
rex1254
LQ Newbie
 
Registered: Aug 2014
Posts: 15

Original Poster
Rep: Reputation: Disabled
Found the problem. When I deleted a directory which has sub-directories in it, IN_DELETE_SELF event was also received along with IN_DELETE event and i was closing the fd of the directory that i was monitoring, in IN_DELETE_SELF event. So now when select was called again could not find the fd and gave me that error.

Please close this thread
 
  


Reply

Tags
filesystem, linux


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
The event->name (inotify) prints all the sub-directories - not the main directory MichaelStein Programming 5 06-22-2014 07:04 AM
[SOLVED] Inotify miss event for directories under /sys/firmware Haidong839 Linux - Kernel 4 09-27-2012 04:58 AM
Windows captions are not highlighted on the task bar when an event occurs galois82 Linux - Newbie 2 12-20-2005 03:03 PM
Netdev_chain notifier call chain doesnt provide the netdev that the event occurs at jinxcat Programming 7 09-15-2005 01:36 AM


All times are GMT -5. The time now is 01:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration