From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.gentoo.org ([140.105.134.102] helo=robin.gentoo.org) by nuthatch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1GE58S-00050k-B2 for garchives@archives.gentoo.org; Fri, 18 Aug 2006 14:15:44 +0000 Received: from robin.gentoo.org (localhost [127.0.0.1]) by robin.gentoo.org (8.13.7/8.13.6) with SMTP id k7IEDeJV006898; Fri, 18 Aug 2006 14:13:40 GMT Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by robin.gentoo.org (8.13.7/8.13.6) with ESMTP id k7IEBhmC029360 for ; Fri, 18 Aug 2006 14:11:44 GMT Received: from localhost (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id 6AF35646E2 for ; Fri, 18 Aug 2006 14:11:43 +0000 (UTC) Received: from smtp.gentoo.org ([127.0.0.1]) by localhost (smtp.gentoo.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 03072-07 for ; Fri, 18 Aug 2006 14:11:32 +0000 (UTC) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTP id 8A4316484D for ; Fri, 18 Aug 2006 14:11:31 +0000 (UTC) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1GE533-0000N0-L1 for gentoo-user@gentoo.org; Fri, 18 Aug 2006 16:10:13 +0200 Received: from p50895d63.dip.t-dialin.net ([80.137.93.99]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 18 Aug 2006 16:10:09 +0200 Received: from costa by p50895d63.dip.t-dialin.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 18 Aug 2006 16:10:09 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: gentoo-user@lists.gentoo.org From: Marco Costa Subject: [gentoo-user] inotify problem Date: Fri, 18 Aug 2006 15:28:09 +0200 Message-ID: <9srgr3-n5s.ln1@legba.gamic.com> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@gentoo.org Reply-to: gentoo-user@lists.gentoo.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: p50895d63.dip.t-dialin.net User-Agent: Thunderbird 1.5.0.5 (X11/20060719) Sender: news X-Virus-Scanned: amavisd-new at gentoo.org X-Spam-Status: No, score=-2.587 required=5.5 tests=[AWL=0.012, BAYES_00=-2.599] X-Spam-Score: -2.587 X-Spam-Level: X-Archives-Salt: a574d973-881e-41ac-bb96-9bed357cc9ad X-Archives-Hash: 409e36e33d844075825dfc25b142fad2 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 #include #include 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