From: Marco Costa <costa@gamic.com>
To: gentoo-user@lists.gentoo.org
Subject: [gentoo-user] inotify problem
Date: Fri, 18 Aug 2006 15:28:09 +0200 [thread overview]
Message-ID: <9srgr3-n5s.ln1@legba.gamic.com> (raw)
Hi.
I am trying to use inotify but something is not correct.
I am using gentoo 2006.0.
kernel: 2.6.17-gentoo-r4
inotify is compiled in.
glibc 2.3.6-r4
What happens:
I initialize inotify, it returns the file descriptor (fd). OK
I add a directory to watch with all flags. It returns the watch descriptor (wd). OK
I read (blocking) the fd. It blocks. OK
-> I touch a file inside the directory I am watching
the read unblocks, but it really returns 0 bytes read and do not block anymore.
Thanks in advance for any clue.
Marco
The code is as follows:
#include <linux/inotify.h>
#include <stdio.h>
#include <asm/unistd.h>
int main( int argc, char **argv )
{
int fd = syscall(__NR_inotify_init);
int wd = syscall(__NR_inotify_add_watch, fd, "/invalid", IN_ALL_EVENTS );
struct inotify_event ev;
char *filename;
uint32_t maxsize = 1024;
int br=0;
filename = (char *) malloc( maxsize * sizeof(char) );
if ( ! filename )
{
puts("Could not allocate 1024 chars. Kill me!");
exit(1);
}
while ( 1 )
{
do {
br = read( fd, (void *) &ev, sizeof(struct inotify_event) );
printf( "Bytes read: %i, sizeof: %i, wd: %i, mask: %X\n", br, sizeof(struct inotify_event), ev.wd, ev.mask );
} while (!br); // I know it is not correct, just to catch the case where br is 0
if ( ev.len > 0 )
{
if ( ev.len > maxsize )
{
maxsize = ev.len;
filename = (char*) realloc( (void*)filename, maxsize * sizeof(char) );
if ( ! filename )
{
printf("Could not reallocate %u chars. Kill me!\n", ev.len);
exit(1);
}
}
read( fd, filename, ev.len );
printf( "%s\n", filename );
}
}
free( filename );
return (0);
}
--
gentoo-user@gentoo.org mailing list
next reply other threads:[~2006-08-18 14:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-18 13:28 Marco Costa [this message]
2006-08-22 9:51 ` [gentoo-user] Re: inotify problem - SOLVED Marco Costa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9srgr3-n5s.ln1@legba.gamic.com \
--to=costa@gamic.com \
--cc=gentoo-user@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox