From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1R4Ed1-0007Yc-Du for garchives@archives.gentoo.org; Thu, 15 Sep 2011 16:17:31 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C4B7A21C14B; Thu, 15 Sep 2011 16:17:20 +0000 (UTC) Received: from mail-ey0-f181.google.com (mail-ey0-f181.google.com [209.85.215.181]) by pigeon.gentoo.org (Postfix) with ESMTP id 62F6321C0FA for ; Thu, 15 Sep 2011 16:16:25 +0000 (UTC) Received: by eyg5 with SMTP id 5so1606065eyg.40 for ; Thu, 15 Sep 2011 09:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=qB/TQW4dx+C8fE9Y4y7eIg/PYwvViJ2hArYhEiAewdE=; b=OM7W+KDPR4TNeZnjaTvqcCx9ZCYU7k3bp6B0wQh9JmoqqeoOtu/X6nAy+JE90K9QOo p82w5Po+MSRo+DVOt/0gsiSn4oJ6FitHwhfIUQrnBhK4JQYKyHIeksYYrJ326TiNkyqR GnNmojeObaxNuhWXbPdFOGhG3yGZCIIMhol6o= Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org MIME-Version: 1.0 Received: by 10.204.156.82 with SMTP id v18mr892958bkw.362.1316103384470; Thu, 15 Sep 2011 09:16:24 -0700 (PDT) Received: by 10.204.155.79 with HTTP; Thu, 15 Sep 2011 09:16:24 -0700 (PDT) In-Reply-To: <1686774.qTVoG11W63@eve> References: <20110912150248.GB3599@acm.acm> <3318888.8i9Hhk9ViB@eve> <1686774.qTVoG11W63@eve> Date: Thu, 15 Sep 2011 12:16:24 -0400 Message-ID: Subject: Re: [gentoo-user] udev + /usr From: Michael Mol To: gentoo-user@lists.gentoo.org Content-Type: text/plain; charset=UTF-8 X-Archives-Salt: X-Archives-Hash: b0d0e2eca21193f415605642996619b7 On Thu, Sep 15, 2011 at 11:43 AM, Joost Roeleveld wrote: > On Thursday, September 15, 2011 11:03:09 AM Michael Mol wrote: >> On Thu, Sep 15, 2011 at 10:48 AM, Joost Roeleveld > wrote: >> The problem with this is that you now need to manage synchronization >> between the kernel event processor and the action processor, which is >> actually more complicated than keeping them together in a >> single-threaded, single-process scenario. > > I don't agree. Why does this need to be synchronized? > > The kernel puts events in the new-dev-event-queue that process 1 picks up. > process 1 creates the /dev-entrie(s) and, if there is an action to be taken, > puts the action in the new-action-event-queue. > > Process 2 will then pick up this action from the new-action-event-queue and > will process this. > > If, as a side-effect, of the action processed by process 2, a new device > appears for the kernel, the kernel will simply put a corresponding event in > the new-dev-event-queue. > > At which state does this need to be synchronized? > We can simply use a pipe-device as, for instance, used for syslog? Let's assume that you have a single-reader, single-writer scenario, and that either the protocol includes a 'record end' marker, or that protocol messages are all of a fixed length and are written atomically. With that out of the way, I don't know. Perhaps no additional synchronization is necessary. You still have a problem with race conditions. Virtually all scripts I've read and written assume a single-threaded environment, but you've defined a two-threaded environment. Here's a potential scenario: 1) A kernel hotplug event comes in when a device is inserted. 2) keventler catches the hotplug event, creates the device node, queues an action event. 3) actionhandler catches the action event, launches the script. 4) The action handler script is still running for the plug-in event, when A kernel hotplug event comes in indicating the device was removed. keventler catches the new hotplug event, removes the device node-- 5) --the scheduler comes around and resumes working on the action handler script. Or perhaps the action handler script was on a different CPU core, and never needed to be unscheduled. The device node it was expecting to be there just disappeared out from under it, violating one of its assumptions, and putting it in an inconsistent state. The inconsistency might occur in a place the script author expected it, or the inconsistency might have occurred in an unexpected place. One presumes the script author didn't sign up to deal with concurrency issues in a bash or python script. 6) keventler registers a new action event, for actioning on the disconnect. 7) actionhandler picks up this new action event, runs the script. Kudos to the script author for thinking ahead to have a shutdown script properly clean up an inconsistent system state left by the partially failed setup script. Steps 3-5 are a classic example of a race condition, and stem from two active threads operating concurrently. Entire programming languages are developed with the core intent of reducing the programmer's need to worry about such things. You _must not_ change the operating environment of a script out from under it. In bash scripts, this is an extraordinarily common pattern: if [ -d $SOME_PATH ]; then // do something fi That's common and accepted; nobody expects a shell script to fail in a scenario like that, because it's is a single-threaded language, and that's been true since its inception. When something keventler does causes the result of "[ -d $SOME_PATH ]" to change after the test had already been done, then the script is only broken because keventler/actionhandler broke it, not because the script was badly written. I've really got to get back to working on stuff I'm being paid for. I'll chat with you guys this weekend. I'm very interested in helping with a reasoned critical perspective, so if this wanders over to a new mailing list or discussion environment, drop me an invite. -- :wq