[systemd-devel] udev event on usb unpluged

christophe.jalady at free.fr christophe.jalady at free.fr
Wed Aug 26 05:43:35 PDT 2015


>can you show how you confirmed your script receive the "add" event, or how the script
>"catch" the event?

Sure: basically I do "echo "USB_$ACTION" >> /tmp/jc.log".
After plug/wait/unplugged/wait I only see lines "USB_add".
See attached my .rules and .sh scripts.


>Can you paste run `udevadm monitor`, plug in your cable/device, wait
>for a second, unplug it, and paste the output?

Well, this is the trick: I cannot add a connection to my device _and_ the usb cable connected to it.
So I am not able to monitor the process directly from my device.
Does the scripts provided are enough to help you understanding my problem ?

Christophe

----- Mail original -----
De: "Tom Yan" <tom.ty89 at gmail.com>
À: "christophe jalady" <christophe.jalady at free.fr>
Cc: "systemd" <systemd-devel at lists.freedesktop.org>
Envoyé: Mercredi 26 Août 2015 08:57:12
Objet: Re: [systemd-devel] udev event on usb unpluged

Can you paste run `udevadm monitor`, plug in your cable/device, wait
for a second, unplug it, and paste the output? Or can you show how you
confirmed your script receive the "add" event, or how the script
"catch" the event?

On 26 August 2015 at 15:35,  <christophe.jalady at free.fr> wrote:
>>> I am not sure about what you mean here. Do you mean that you can't see
>> any remove event with `udevadm monitor` when you unplug the "cable"?
>
> yes, my script never receive the "remove" event (_but_ receive the "add" event).
>
>
>>> Also do you really mean a "usb cable" without any device connected to
>> it on the other end?
>
> No, the cable is connected to another device. So I want the "remove" event when the cable is unplugged from one of the device (my device or the other one).
>
>
>> Unless you have a very specific to match with, I wonder if it's a good
>> idea to unload the module by a remove event,
>> ...what if there are two "cables"/devices using the module?
>
> Well, my setup is really specific (small robotic device), so it safe to consider only one cable connected.
>
>
>>Also it seems to be g_mass_storage is just the module for setting up
>>dummy or emulating an mass storage device. Why would you want it to
>>depend on a usb "cable"/device?
>
> This is the bigger picture:
> My device is a small robotic device. To send a file on it, I that users just copy files like they do with  mass-storage usb-key.
> So: On usb-plugged: I load the module k_mass_storage: the other device see a new mass-storage device appearing, copy files and then umount/unplugged the cable.
> When the cable is unplugged, I want to trigger an action on my device (processing the files copied).
>
> Christophe
>
>
>
> ----- Mail original -----
> De: "Tom Yan" <tom.ty89 at gmail.com>
> À: "christophe jalady" <christophe.jalady at free.fr>
> Cc: "systemd" <systemd-devel at lists.freedesktop.org>
> Envoyé: Mercredi 26 Août 2015 04:37:40
> Objet: Re: [systemd-devel] udev event on usb unpluged
>
> Also it seems to be g_mass_storage is just the module for setting up
> dummy or emulating an mass storage device. Why would you want it to
> depend on a usb "cable"/device?
>
> On 26 August 2015 at 11:21, Tom Yan <tom.ty89 at gmail.com> wrote:
>> I am not sure about what you mean here. Do you mean that you can't see
>> any remove event with `udevadm monitor` when you unplug the "cable"?
>> Also do you really mean a "usb cable" without any device connected to
>> it on the other end?
>>
>> By the way the rule you set up is so broad that the script will
>> basically be run on every boot or udevadm trigger.
>>
>> Unless you have a very specific to match with, I wonder if it's a good
>> idea to unload the module by a remove event, because, for example,
>> what if there are two "cables"/devices using the module?
>>
>> On 26 August 2015 at 04:17,  <christophe.jalady at free.fr> wrote:
>>> Hi,
>>>
>>> I would like to receive an event (actually run a script) when I plug/unplugged an usb cable.
>>> I tried to use udev with this simple rule:
>>> SUBSYSTEM=="usb",RUN+="/var/local/usb-changed.sh"
>>>
>>> I do receive the "add" event when I plug the usb cable: just perfect !
>>>
>>> But I never receive the "remove" event.
>>> Any idea why ?
>>>
>>> More information:
>>> I use linux kernel v3.16.
>>> When the cable is plugged, I load the kernel module "g_mass_storage", this work great. My need is to unload the module when the usb cable is unplugged (note it would be even better if I receive an event when the mass-storage is unmounted by the other host, but I do not have any idea where to look for.)
>>>
>>> Thanks by advance for any hint.
>>>
>>> Christophe
>>> _______________________________________________
>>> systemd-devel mailing list
>>> systemd-devel at lists.freedesktop.org
>>> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 95-usb.rules
Type: application/octet-stream
Size: 50 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20150826/204a66b1/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: usb-changed.sh
Type: application/x-shellscript
Size: 523 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20150826/204a66b1/attachment.bin>


More information about the systemd-devel mailing list