From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 22 15:24:21 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7AF3016A423 for ; Wed, 22 Jun 2005 15:24:21 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: from mv.twc.weather.com (mv.twc.weather.com [65.212.71.225]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3274143D1D for ; Wed, 22 Jun 2005 15:24:21 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: from [10.50.41.231] (Not Verified[65.202.103.25]) by mv.twc.weather.com with NetIQ MailMarshal (v6, 0, 3, 8) id ; Wed, 22 Jun 2005 11:37:51 -0400 From: John Baldwin To: freebsd-hackers@freebsd.org Date: Wed, 22 Jun 2005 11:21:18 -0400 User-Agent: KMail/1.8 References: <42887FEE.3000705@kepa.fi> <20050516125109.GF33622@wombat.fafoe.narf.at> <200506211116.32625.jhb@FreeBSD.org> In-Reply-To: <200506211116.32625.jhb@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-6" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200506221121.19848.jhb@FreeBSD.org> Cc: Stefan Farfeleder , Juho Vuori Subject: Re: Bug in devinfo or something wrong with me? 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: Wed, 22 Jun 2005 15:24:22 -0000 On Tuesday 21 June 2005 11:16 am, John Baldwin wrote: > On Monday 16 May 2005 08:51 am, Stefan Farfeleder wrote: > > On Mon, May 16, 2005 at 02:11:42PM +0300, Juho Vuori wrote: > > > The below included simple program reliably printfs "error 4\n" on > > > 5.4-RELEASE. Am I understanding something wrong or is this a bug in > > > libdevinfo? > > > > There is indeed a bug in libdevinfo. > > > > > To continue on this however, if you put say sleep(5) between > > > devinfo_free() and the second devinfo_init() and manage to change the > > > device configuration during the sleep (tested with pluggin in/out a USB > > > memory), the program terminates with no errors. I've run into other > > > oddities with devinfo as well, but in much more complex situations so > > > they might just as well be variations of this simple example. > > > > > > if (devinfo_init()) { > > > > devinfo_init() initialises the devinfo_dev tailq, devinfo_generation and > > sets devinfo_initted to 1. > > > > > devinfo_free(); > > > > devinfo_free() clears devinfo_dev and sets devinfo_initted to 0 but > > devinfo_generation keeps its value. > > > > > if (devinfo_init()) { > > > > Now devinfo_dev doesn't get filled because ubus.ub_generation == > > devinfo_generation. > > > > Here is a patch that resets devinfo_generation to 0 in devinfo_free(). > > The whole file can probably be simplified a bit due to this bug. > > > > Stefan > > I think the intent is actually so that you can call devinfo_init() > periodically without calling devinfo_free() to make sure the tree is up to > date. However, the generation should still be cleared when free() is > called. IOW, if you wanted to have a program that would poll the kernel > each second to get the current tree, it would call devinfo_init() in a loop > and only call devinfo_free() at program exit. This would let > devinfo_init() cache data if the device tree doesn't change. I'll try to > get the patch into the tree. I just committed it to HEAD and will MFC in a week or so. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org