mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Thomas Stewart <thomas@stewarts.org.uk>
Cc: linux-kernel@vger.kernel.org
Subject: Re: udev remove event not sent untill the device is closed
Date: Fri, 1 Oct 2004 10:53:12 -0700	[thread overview]
Message-ID: <20041001175312.GB14015@kroah.com> (raw)
In-Reply-To: <200409272252.36016.thomas@stewarts.org.uk>

On Mon, Sep 27, 2004 at 10:52:36PM +0100, Thomas Stewart wrote:
> Hi,
> 
> I'm running 2.6.8.1 with udev-031. I have a usb2serial converter which has a 
> udev rule to give it a persistent name in my dev tree. I want to run a script 
> when the converter is attached, and another when the converter is removed.
> 
> I tried both the /etc/hotplug.d and /etc/dev.d methods to do this (I like the 
> dev.d method better as I can use my persistent device name). Unfortunately I 
> ran into problems.
> 
> I'm catching the tty event as it sets $DEVPATH to something useful 
> (e.g. /devices/sys/class/tty/ttyUSB0). And then running a different script 
> depending on $ACTION.
> 
> I made a short script to do this, and put it in /etc/dev.d/default/ttyUSB.dev:
> #!/bin/sh
> test "$1" != "tty" && exit
> test "$ACTION" == "add"    && /usr/local/bin/on
> test "$ACTION" == "remove" && /usr/local/bin/off
> 
> (I removed the various error checking that actually makes sure the tty event 
> in question was actually the serial converter, and not some other device.)
> 
> This works fine, I can add and remove the converter to my hearts content and 
> both scripts run accordingly.
> 
> However, if I attach the device, open it with say a "cat /dev/ttyUSB0" and 
> then remove the device. No tty events get sent untill I kill the cat.

This is because the tty device remains until the last userspace process
releases the device.  You might want to trigger your script off of the
removal of the USB device instead.

Hope this helps,

greg k-h

  reply	other threads:[~2004-10-01 18:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-27 21:52 Thomas Stewart
2004-10-01 17:53 ` Greg KH [this message]
2004-10-02 15:31   ` Thomas Stewart

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=20041001175312.GB14015@kroah.com \
    --to=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thomas@stewarts.org.uk \
    /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

all inboxes | Powered by JetHome®