From owner-freebsd-hackers@FreeBSD.ORG Tue Mar 6 15:39:57 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 992D2106566C; Tue, 6 Mar 2012 15:39:57 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 72E278FC13; Tue, 6 Mar 2012 15:39:57 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [96.47.65.170]) by cyrus.watson.org (Postfix) with ESMTPSA id 2CB8C46B52; Tue, 6 Mar 2012 10:39:57 -0500 (EST) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 8743CB974; Tue, 6 Mar 2012 10:39:56 -0500 (EST) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Tue, 6 Mar 2012 10:24:06 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p10; KDE/4.5.5; amd64; ; ) References: <4F550227.2010006@FreeBSD.org> In-Reply-To: <4F550227.2010006@FreeBSD.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201203061024.06389.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 06 Mar 2012 10:39:56 -0500 (EST) Cc: Sergey Matveychuk Subject: Re: watching for a directory with kqueue X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Mar 2012 15:39:57 -0000 On Monday, March 05, 2012 1:12:55 pm Sergey Matveychuk wrote: > Hi. > > I've met a problem with the subj. Could you help? > > I'm watching for a directory: > EV_SET(kq_change_list, fd, EVFILT_VNODE, > EV_ADD | EV_ENABLE | EV_ONESHOT, > NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB, > 0, 0); > > When the directory changed, I read its contens with opendir, like that: > struct kq_event kq_event[1000]; > ... > while(1) { > n = kevent(kq, kq_change_list, chlist_used, kq_event, 1000, NULL); > for(i = 0; i < n; i++) { > if(kq_event[i].fflags & NOTE_EXTEND || kq_event[i].fflags & NOTE_WRITE) { > opendir(.....) > > It works when I create a few files (1-3), but when I create 10 files > with touch(1) I see only 3-6 files with opendir. I've got only one event > with kevent() (n=1). Looks like I should got a few events, but I did > not. Could you give an advice how to get all created files? The problem is your kevent can fire after just one file is created, so you can run opendir() before all 10 files are created. If you want the keven to keep firing, you need to not use EV_ONESHOT. Instead, you probably want to use EV_CLEAR. That would let you get multiple events for the directory, and by the last one, all 10 files should be present. -- John Baldwin