From owner-freebsd-hackers@FreeBSD.ORG Tue Mar 5 16:53:11 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 3E12E35F for ; Tue, 5 Mar 2013 16:53:11 +0000 (UTC) (envelope-from bright@mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 29FFCF01 for ; Tue, 5 Mar 2013 16:53:10 +0000 (UTC) Received: from Alfreds-MacBook-Pro-9.local (c-67-180-208-218.hsd1.ca.comcast.net [67.180.208.218]) by elvis.mu.org (Postfix) with ESMTPSA id EA7F11A3C22; Tue, 5 Mar 2013 08:53:08 -0800 (PST) Message-ID: <513622F2.20902@mu.org> Date: Tue, 05 Mar 2013 08:53:06 -0800 From: Alfred Perlstein User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/20130216 Thunderbird/17.0.3 MIME-Version: 1.0 To: Dirk Engling Subject: Re: pop filters from kqueue References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Mar 2013 16:53:11 -0000 On 3/5/13 8:03 AM, Dirk Engling wrote: > Dear fellow FreeBSD hackers, > > while writing a daemon that uses a kqueue to keep track of forked > processes and pipes to userland client code etc, I noticed a lack of > features to implement a proper shutdown without holding data redundantly. > > When my daemon quits, I can not ask the kqueue for my installed > filters and get back the udata I passed to the kqueue. > > This is unfortunate, because I like the idea of having only one owner > per memory allocation. The most obvious use would be a per-fd-state > held in a memory block. When passing it to kevent() via the udata > entry, I would make this filter the owner of my allocation. > > However, when gracefully shutting down, my daemon has no way of > retrieving all the values passed to the filters. For most cases that > may be okay: > memory allocations will just be thrown away on exit(), anyway. > > But once I need to clean up external state, like sending signals to > processes I installed an EVFILT_PROC for etc, I need to keep a > redundant list of pids and the associated udata. This violates the > rule of strict ownership and introduces room for inconsistencies. > > Is there a specific reason I have overlooked that would forbid popping > untriggered filters from my kqueue? Or is there even a way to do so > that I have missed? > I'm not sure if kqueue support this, however adding such a facility might be OK. Another way to handle this is just to make your udata pointers all point to items in a doubly linked list with the head structure aware of which kqueue. Then at the end you can just traverse the list of items you have not yet popped off. The only pain here is that it requires managing a doubly linked list and additional pointer dereferences. -Alfred