mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* udev remove event not sent untill the device is closed
@ 2004-09-27 21:52 Thomas Stewart
  2004-10-01 17:53 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Stewart @ 2004-09-27 21:52 UTC (permalink / raw)
  To: linux-kernel

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.

I want to be able to run the script when I remove the converter. (I actually 
want the remove script to kill the process that has the device open.)

I found it hard to use the usb events because when they run, $DEVPATH no 
longer exists. Which means I have no idea which converter was removed.

(Can replies be CC'ed to me as I'm not subscribed. Thanks)

Regards
-- 
Tom

PGP Fingerprint [DCCD 7DCB A74A 3E3B 60D5  DF4C FC1D 1ECA 68A7 0C48]
PGP Publickey   [http://www.stewarts.org.uk/public-key.asc]
PGP ID  [0x68A70C48]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: udev remove event not sent untill the device is closed
  2004-09-27 21:52 udev remove event not sent untill the device is closed Thomas Stewart
@ 2004-10-01 17:53 ` Greg KH
  2004-10-02 15:31   ` Thomas Stewart
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2004-10-01 17:53 UTC (permalink / raw)
  To: Thomas Stewart; +Cc: linux-kernel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: udev remove event not sent untill the device is closed
  2004-10-01 17:53 ` Greg KH
@ 2004-10-02 15:31   ` Thomas Stewart
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Stewart @ 2004-10-02 15:31 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel

On Friday 01 October 2004 18:53, you wrote:
> On Mon, Sep 27, 2004 at 10:52:36PM +0100, Thomas Stewart wrote:
> > 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.

I tried that method instead and it works. Now that I think about it more it 
does make more sense.

For anyone else doing something similar this is what I ended up with 
http://www.stewarts.org.uk/stuff/ttyUSB.hotplug not exactly elegant but it 
works.

Thanks
-- 
Tom

PGP Fingerprint [DCCD 7DCB A74A 3E3B 60D5  DF4C FC1D 1ECA 68A7 0C48]
PGP Publickey   [http://www.stewarts.org.uk/public-key.asc]
PGP ID  [0x68A70C48]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-10-02 15:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-27 21:52 udev remove event not sent untill the device is closed Thomas Stewart
2004-10-01 17:53 ` Greg KH
2004-10-02 15:31   ` Thomas Stewart

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®