public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Joost Roeleveld <joost@antarean.org>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] udev + /usr
Date: Thu, 15 Sep 2011 18:37:03 +0200	[thread overview]
Message-ID: <1373295.Fv0tYkBvOy@eve> (raw)
In-Reply-To: <CA+czFiAjvXz8EbryZNix0+aWPJKOC+zssubigPKbEV0qpLrHcQ@mail.gmail.com>

On Thursday, September 15, 2011 12:16:24 PM Michael Mol wrote:
> On Thu, Sep 15, 2011 at 11:43 AM, Joost Roeleveld <joost@antarean.org> 
wrote:
> > On Thursday, September 15, 2011 11:03:09 AM Michael Mol wrote:
> >> On Thu, Sep 15, 2011 at 10:48 AM, Joost Roeleveld <joost@antarean.org>
> > 
> > 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.

Ok, didn't think of this scenario. Thank you for pointing this out to me.
Your pseudo-code would be better then, except there should be some way of 
delaying action-tasks based on wether or not required files (including 
dependencies) are available. Or a retry-queue that retries an action a few 
times with certain intervals. This, however, will be more difficult to 
implement especially with the race-condition you mentioned.

> 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.

We will, but for now, why not keep it on here? :)

Was wondering, does udev actually support actions for when a device is 
removed?
Ok, just checked on my server and it does. All nicely pointing to scripts in 
/etc/....

Also, anyone knows how udev handles the scenario where a device is removed 
while the script is still running? Wouldn't it fail mid-execution because the 
kernel no longer allows actions with that device?

--
Joost



  reply	other threads:[~2011-09-15 16:38 UTC|newest]

Thread overview: 254+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-12 15:02 [gentoo-user] udev + /usr Alan Mackenzie
2011-09-12 15:33 ` Michael Schreckenbauer
2011-09-12 17:17   ` Alan Mackenzie
2011-09-12 17:39     ` Michael Mol
2011-09-12 18:08       ` Michael Schreckenbauer
2011-09-12 18:37       ` Canek Peláez Valdés
2011-09-12 19:00         ` Michael Mol
2011-09-12 19:35           ` Canek Peláez Valdés
2011-09-12 19:52             ` Michael Mol
2011-09-12 20:24             ` Alex Schuster
2011-09-13  7:08               ` Joost Roeleveld
2011-09-12 20:31             ` Alan Mackenzie
2011-09-13  3:18               ` Peter Humphrey
2011-09-13  7:15                 ` Joost Roeleveld
2011-09-13  7:01               ` Paul Colquhoun
2011-09-13 18:15                 ` Dale
2011-09-12 20:16           ` David W Noon
2011-09-12 19:07         ` Michael Schreckenbauer
2011-09-12 19:18           ` Michael Mol
2011-09-12 19:41             ` Michael Schreckenbauer
2011-09-12 20:07               ` Michael Mol
2011-09-12 20:57                 ` Alan McKinnon
2011-09-12 22:00                   ` Michael Schreckenbauer
2011-09-12 23:31                     ` Canek Peláez Valdés
2011-09-13  7:28                       ` Joost Roeleveld
2011-09-13  8:52                       ` Michael Schreckenbauer
2011-09-12 21:14                 ` Pandu Poluan
2011-09-13  2:07                   ` Walter Dnes
2011-09-13  7:25                 ` Joost Roeleveld
2011-09-12 19:56         ` Dale
2011-09-13  3:28         ` Walter Dnes
2011-09-13  7:04           ` Neil Bothwick
2011-09-13 15:21             ` Walter Dnes
2011-09-13 15:38               ` Michael Schreckenbauer
2011-09-13 15:49               ` Neil Bothwick
2011-09-13 16:56                 ` Joost Roeleveld
2011-09-12 17:50     ` Michael Schreckenbauer
2011-09-13 14:40       ` Alan Mackenzie
2011-09-13 14:55         ` Michael Schreckenbauer
2011-09-13 15:38           ` Alan Mackenzie
2011-09-13 16:14             ` Canek Peláez Valdés
2011-09-13 20:35               ` Alan McKinnon
2011-09-13 20:52                 ` Canek Peláez Valdés
2011-09-13 20:57                   ` Michael Mol
2011-09-13 21:10                     ` Canek Peláez Valdés
2011-09-13 21:30                       ` Michael Schreckenbauer
2011-09-13 21:53                         ` Canek Peláez Valdés
2011-09-13 22:10                           ` Michael Schreckenbauer
2011-09-13 22:33                             ` Canek Peláez Valdés
2011-09-14  5:52                               ` Joost Roeleveld
2011-09-14 14:30                                 ` Canek Peláez Valdés
2011-09-14 18:36                                   ` Dale
2011-09-14 18:55                                     ` Canek Peláez Valdés
2011-09-14 23:06                                       ` William Kenworthy
2011-09-15  0:00                                         ` Dale
2011-09-15 20:42                                     ` Mike Edenfield
2011-09-15 21:01                                       ` Michael Mol
2011-09-15 21:16                                       ` Joost Roeleveld
2011-09-15 21:28                                         ` Canek Peláez Valdés
2011-09-15 22:05                                         ` Mike Edenfield
2011-09-15 22:26                                           ` Mark Knecht
2011-09-15 22:44                                             ` Canek Peláez Valdés
2011-09-16  8:46                                               ` Joost Roeleveld
2011-09-16 10:00                                                 ` Alan McKinnon
2011-09-16 10:54                                                   ` Joost Roeleveld
2011-09-16 13:03                                                     ` Alan McKinnon
2011-09-15  7:01                                   ` Joost Roeleveld
2011-09-15 13:47                                     ` Michael Mol
2011-09-15 14:11                                       ` Joost Roeleveld
2011-09-15 14:32                                         ` Michael Mol
2011-09-15 14:48                                           ` Joost Roeleveld
2011-09-15 14:58                                             ` Canek Peláez Valdés
2011-09-15 17:43                                               ` Canek Peláez Valdés
2011-09-15 21:25                                                 ` Joost Roeleveld
2011-09-15 21:34                                                   ` Canek Peláez Valdés
2011-09-16  8:54                                                     ` Joost Roeleveld
2011-09-18  7:29                                                   ` Walter Dnes
2011-09-15 15:03                                             ` Michael Mol
2011-09-15 15:16                                               ` Michael Schreckenbauer
2011-09-15 15:37                                                 ` Michael Mol
2011-09-15 15:43                                               ` Joost Roeleveld
2011-09-15 16:16                                                 ` Michael Mol
2011-09-15 16:37                                                   ` Joost Roeleveld [this message]
2011-09-15 15:13                                             ` Michael Schreckenbauer
2011-09-15 17:59                                               ` Mick
2011-09-15 19:04                                                 ` Canek Peláez Valdés
2011-09-15 19:17                                                   ` Neil Bothwick
2011-09-15 21:30                                                   ` Joost Roeleveld
2011-09-15 21:38                                                     ` Canek Peláez Valdés
2011-09-16  8:59                                                       ` Joost Roeleveld
2011-09-16  9:29                                                         ` Pandu Poluan
2011-09-16 14:57                                                           ` Canek Peláez Valdés
2011-09-16 15:57                                                             ` Dale
2011-09-16 16:11                                                               ` Canek Peláez Valdés
2011-09-16 16:20                                                               ` Mark Knecht
2011-09-16 17:09                                                                 ` Dale
2011-09-16 16:21                                                               ` Pandu Poluan
2011-09-17  6:06                                                                 ` Joost Roeleveld
2011-09-16 18:45                                                               ` Carlos Hendson
2011-09-19  0:58                                                 ` Walter Dnes
2011-09-15 14:57                                           ` Canek Peláez Valdés
2011-09-15 15:08                                             ` Michael Mol
2011-09-15 15:37                                             ` Joost Roeleveld
2011-09-15 18:15                                               ` Neil Bothwick
2011-09-15 21:32                                                 ` Joost Roeleveld
2011-09-15 17:37                                             ` pk
2011-09-15 21:34                                               ` Joost Roeleveld
2011-09-15 20:05                                             ` Sebastian Beßler
2011-09-15 20:27                                               ` Canek Peláez Valdés
2011-09-15 20:53                                                 ` Sebastian Beßler
2011-09-15 21:05                                                   ` Canek Peláez Valdés
2011-09-16  9:08                                                     ` Joost Roeleveld
2011-09-16 14:53                                                       ` Canek Peláez Valdés
2011-09-17  6:45                                                         ` Joost Roeleveld
2011-09-17  7:04                                                           ` Joost Roeleveld
2011-09-17 14:59                                                             ` Canek Peláez Valdés
2011-09-17 12:33                                                           ` Alan McKinnon
2011-09-17 14:50                                                           ` Canek Peláez Valdés
2011-09-17 15:41                                                             ` Michael Mol
2011-09-17 18:36                                                               ` Canek Peláez Valdés
2011-09-17 19:24                                                                 ` Michael Mol
2011-09-17 21:13                                                                   ` Canek Peláez Valdés
2011-09-18 19:13                                                                     ` Neil Bothwick
2011-09-17 23:00                                                                   ` Alan McKinnon
2011-09-17 23:31                                                                     ` Michael Mol
2011-09-17 23:45                                                                       ` Canek Peláez Valdés
2011-09-17 23:50                                                                         ` Michael Mol
2011-09-18  7:37                                                                       ` Alan McKinnon
2011-09-18  9:23                                                                         ` [gentoo-user] [OT rant] " pk
2011-09-18 10:03                                                                           ` Volker Armin Hemmann
2011-09-18 10:44                                                                             ` pk
2011-09-18 12:32                                                                               ` Volker Armin Hemmann
2011-09-18 12:56                                                                                 ` Alan McKinnon
2011-09-18 16:55                                                                                   ` pk
2011-09-18 17:41                                                                                     ` Indi
2011-09-18 18:13                                                                                       ` pk
2011-09-18 19:08                                                                                     ` Alan McKinnon
2011-09-18 20:48                                                                                     ` Volker Armin Hemmann
2011-09-20  0:20                                                                                       ` Walter Dnes
2011-09-20 16:50                                                                                         ` Volker Armin Hemmann
2011-09-20 17:10                                                                                           ` Alex Schuster
2011-09-20 17:28                                                                                             ` Michael Mol
2011-09-20 17:33                                                                                               ` Mark Knecht
2011-09-20 17:54                                                                                               ` Alex Schuster
2011-09-20 17:19                                                                                           ` Thanasis
2011-09-20 17:30                                                                                             ` Volker Armin Hemmann
2011-09-21 16:54                                                                                     ` Roman Dobosz
2011-09-18 13:19                                                                                 ` pk
2011-09-18 13:31                                                                                   ` Canek Peláez Valdés
2011-09-18 17:43                                                                                     ` pk
2011-09-18 19:52                                                                                       ` Michael Mol
2011-09-18 21:06                                                                                         ` Volker Armin Hemmann
2011-09-19 19:23                                                                                           ` Alan McKinnon
2011-09-19 16:23                                                                                         ` pk
2011-09-19 16:37                                                                                           ` Michael Mol
2011-09-19 17:42                                                                                             ` Volker Armin Hemmann
2011-09-19 18:02                                                                                               ` Michael Mol
2011-09-19 19:20                                                                                                 ` Alan McKinnon
2011-09-19 19:42                                                                                                   ` Michael Mol
2011-09-19 20:44                                                                                                   ` Volker Armin Hemmann
2011-09-19 22:13                                                                                                 ` Neil Bothwick
2011-09-19  6:21                                                                                     ` Paul Colquhoun
2011-09-19 16:28                                                                                       ` Volker Armin Hemmann
2011-09-18 13:37                                                                                   ` Volker Armin Hemmann
2011-09-18 13:58                                                                                     ` Michael Mol
2011-09-18 21:07                                                                                       ` Volker Armin Hemmann
2011-09-19 17:13                                                                                         ` Michael Mol
2011-09-18 13:15                                                                             ` Canek Peláez Valdés
2011-09-18 13:33                                                                               ` Volker Armin Hemmann
2011-09-22 15:06                                                                     ` [gentoo-user] " Michael Orlitzky
2011-09-17 21:03                                                                 ` pk
2011-09-17 21:25                                                                   ` Canek Peláez Valdés
2011-09-19  8:30                                                                   ` [gentoo-user] " Nicolas Sebrecht
2011-09-19 14:22                                                                     ` Alan McKinnon
2011-09-19 14:41                                                                       ` Michael Schreckenbauer
2011-09-19 16:36                                                                         ` Volker Armin Hemmann
2011-09-19 17:25                                                                           ` Michael Schreckenbauer
2011-09-19 17:43                                                                             ` Volker Armin Hemmann
2011-09-19 17:59                                                                               ` Michael Schreckenbauer
2011-09-19 18:06                                                                               ` Michael Mol
2011-09-19 19:12                                                                               ` Alan McKinnon
2011-09-19 20:46                                                                                 ` Volker Armin Hemmann
2011-09-19 21:22                                                                                   ` Alan McKinnon
2011-09-20  2:00                                                                               ` Indi
2011-09-19 18:28                                                                       ` pk
2011-09-20 10:13                                                                       ` James Broadhead
2011-09-20 23:12                                                                         ` Alan McKinnon
2011-09-20 23:47                                                                           ` Dale
2011-09-21 17:55                                                                             ` Mick
2011-09-17 18:43                                                             ` [gentoo-user] " Canek Peláez Valdés
2011-09-18 14:47                                                               ` Joost Roeleveld
2011-09-18 15:32                                                                 ` Pandu Poluan
2011-09-15 20:26                                       ` Alan McKinnon
2011-09-14  9:06                       ` Neil Bothwick
2011-09-14 14:37                         ` Canek Peláez Valdés
2011-09-14 14:49                           ` Michael Mol
2011-09-14 15:36                             ` Neil Bothwick
2011-09-14 15:43                               ` Michael Mol
2011-09-14 16:05                                 ` Allan Gottlieb
2011-09-14 16:10                                   ` Canek Peláez Valdés
2011-09-14 18:59                                   ` Neil Bothwick
2011-09-14 22:37                                     ` Peter Humphrey
2011-09-14 23:43                                       ` Neil Bothwick
2011-09-14 23:51                                         ` Peter Humphrey
2011-09-14 15:35                           ` Neil Bothwick
2011-09-14 16:07                             ` Canek Peláez Valdés
2011-09-14 16:40                               ` Sebastian Beßler
2011-09-15  7:37                                 ` Joost Roeleveld
2011-09-15  7:26                           ` Joost Roeleveld
2011-09-14 10:25                       ` Alan Mackenzie
2011-09-14 14:10                         ` Mick
2011-09-14 14:19                           ` Michael Mol
2011-09-14 14:56                             ` Canek Peláez Valdés
2011-09-14 14:50                           ` Canek Peláez Valdés
2011-09-14 14:47                         ` Canek Peláez Valdés
2011-09-14 15:04                         ` Stroller
2011-09-14 21:34                           ` Alan Mackenzie
2011-09-14 22:05                             ` Really OT now (Re: [gentoo-user] udev + /usr) Michael Schreckenbauer
2011-09-14 22:35                               ` Michael Mol
2011-09-15 18:58                                 ` IDE for C/C++ (Was: " David W Noon
2011-09-15 19:16                                   ` Michael Mol
2011-09-15 19:47                                     ` Leonardo Guilherme
2011-09-15 19:59                                       ` Chris Brennan
2011-09-15 20:05                                         ` Michael Mol
2011-09-15 21:39                                           ` Joost Roeleveld
2011-09-16  0:22                                         ` Michael Mol
2011-09-16  9:43                                           ` Michael Schreckenbauer
2011-09-16 12:30                                           ` Mike Edenfield
2011-09-16 12:46                                             ` Michael Mol
2011-09-16 13:10                                           ` Alan Mackenzie
2011-09-15 21:37                                     ` Alexander Tanyukevich
2011-09-15 21:38                                       ` Alexander Tanyukevich
2011-09-15 20:09                                 ` [gentoo-user] Re: Really OT now (Re: " Nikos Chantziaras
2011-09-15 14:10                             ` [gentoo-user] udev + /usr Stroller
2011-09-13 16:24             ` David W Noon
2011-09-13 23:00         ` Mike Edenfield
2011-09-13 12:38     ` Mike Edenfield
2011-09-13 12:45       ` Neil Bothwick
2011-09-13 15:09         ` Stroller
2011-09-13 15:46           ` Neil Bothwick
2011-09-13 23:10         ` Mike Edenfield
2011-09-13 12:59       ` Michael Mol
2011-09-14 20:41       ` pk
2011-09-12 20:45   ` Alan McKinnon
2011-09-12 15:35 ` Canek Peláez Valdés
2011-09-12 15:59   ` Michael Schreckenbauer
2011-09-13  7:28     ` Paul Colquhoun
2011-09-12 16:21   ` Dale
2011-09-12 16:42     ` Canek Peláez Valdés
2011-09-12 16:52       ` Michael Schreckenbauer
2011-09-12 18:26         ` Canek Peláez Valdés
2011-09-12 18:54           ` Michael Schreckenbauer
2011-09-12 16:55       ` Michael Mol
2011-09-12 20:34       ` Alan McKinnon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1373295.Fv0tYkBvOy@eve \
    --to=joost@antarean.org \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox