How to detect USB disconnect device using udev rules?

I have two LCDs with Xorg xinerama function. Each LCD screen is equipped with a touch screen that is connected to the corresponding USB lines.

Looking at the file '/ var / log / messages', I see the following:

kernel: input: Analog Resistive as /class/input/input0 kernel: input: USB HID v1.01 Mouse [Analog Resistive] on usb-0000:00:1d.3-1 kernel: input: Analog Resistive as /class/input/input1 kernel: input: USB HID v1.01 Mouse [Analog Resistive] on usb-0000:00:1d.3-2 

For some reason, at some point, the USB bus looks like reset (or something strange), and my two touch screens are upside down (press the left LCD and the mouse moves to the right, and if I click on the right LCD -Display mouse moves to the left).

To try and debug the problem, I tried to write a udev rule to register when my devices get reset / disconnected (or something else). But it seems that udev will report full information (product, manufacturer, idProduct, idVendor, etc.) on the device, when it connects, but when removed, it does not give anything but a few bus numbers. Why is this?

When I get ACTION == "remove", KERNEL == "input *" rule, I don’t know what device it is! Does anyone know about this?

+4
source share
3 answers

I would suggest first checking the udev events on the device to “delete” the event by doing, for example. udevadm monitor --kernel --property --subsystem-match=usb and disconnect devices one by one and compare outputs. Here, on one mouse trip, I get two events:

 KERNEL[6680.737678] remove /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0 (usb) ACTION=remove DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0 DEVTYPE=usb_interface INTERFACE=3/1/2 MODALIAS=usb:v09DAp000Ad0034dc00dsc00dp00ic03isc01ip02in00 PRODUCT=9da/a/34 SEQNUM=2835 SUBSYSTEM=usb TYPE=0/0/0 KERNEL[6680.739577] remove /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2 (usb) ACTION=remove BUSNUM=002 DEVNAME=/dev/bus/usb/002/006 DEVNUM=006 DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2 DEVTYPE=usb_device MAJOR=189 MINOR=133 PRODUCT=9da/a/34 SEQNUM=2836 SUBSYSTEM=usb TYPE=0/0/0 

You can write your rule by calling a script that should do some work after examining some specific environment variable. A rule can be as simple as

 SUBSYSTEM=="usb", ACTION=="remove", RUN+="/usr/local/sbin/usbdevgone.sh" 

In your case, I suggest checking $ DEVPATH inside usbdevgone.sh, as they should be different for your two identical devices. You can also pass devpath (this is the path in / sys / filesystem) as an argument to your script, like this (see man udev for a list of available substitutions ):

 SUBSYSTEM=="usb", ACTION=="remove", RUN+="/usr/local/sbin/usbdevgone.sh $devpath" 

Remember to notify udevd of your new or changed rule with udevadm control --reload-rules

+2
source

I ran into the same problem on Linux. Information sent for deletion is minimal and cannot be used to uniquely identify the device to be deleted. I used PHYDEVPATH (which is unique for connecting and disconnecting for this machine and USB port), but unfortunately this was deprecated in later versions of udev .

0
source

I wrote an application with similars functions, and I solved the problem of deploying a daemon with a single udev_device storage udev_device . Therefore, when I detect some remove even from udev_monitor , I check to see if there is any device in the deamon device list. What is missing is this device is disconnected. Thus, I can get data about disconnected devices.

0
source

All Articles