0

I am trying to match a device using udev and run a command every time the device is connected (via RUNS). The device (a V4L2 USB camera) is always connected to the same USB port, so I thought I could rely on the KERNELS attribute to match it. I always thought that the sysfs path of a device would be persistent, but I have seen different paths and KERNELS values for the same device connected to the same USB port:

$ udevadm info -a /dev/video0
...
  looking at device '/devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1.4/3-1.4:1.0/video4linux/video0':
    KERNEL=="video0"
    SUBSYSTEM=="video4linux"
    DRIVER==""
...

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1.4/3-1.4:1.0':
    KERNELS=="3-1.4:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="uvcvideo"
...

Now, after a reboot, I got different values:

$ udevadm info -a /dev/video0
...
  looking at device '/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/video4linux/video0':
    KERNEL=="video0"
    SUBSYSTEM=="video4linux"
    DRIVER==""
...

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0':
    KERNELS=="1-3:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="uvcvideo"
...

How can I write a reliable udev rule that matches the devices connected to that USB port?

I noticed that the path in /dev/v4l/by-path does not change, even if the path in /sysfs changes: /dev/v4l/by-path/pci-0000:00:14.0-usb-0:3:1.0-video-index0 (but I don't know how to use that to my advantage).

1 Answer 1

0

It turns out that the KERNELS attributes are not reliable for doing such USB port based matching. However, I figured out how to utilize that by-path symlink: Match via SYMLINK=="...".

For the device in question, this would read

SYMLINK=="v4l/by-path/pci-0000:00:14.0-usb-0:3:1.0-video-index0"

There is also the ID_PATH device property that can be used in a similar way.

Symlinks and device properties can be listed using

udevadm info -q all [device_path_or_name]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .