2

Я хочу создать правило udev для выполнения, когда моя гарнитура подключена. Поэтому я следовал этому уроку, но мое правило не работает.

Выход из

udevadm monitor --environment | fgrep 'DEVNAME=/dev'

после подключения гарнитуры есть:

DEVNAME=/dev/bus/usb/001/023  
DEVNAME=/dev/snd/controlC2  
DEVNAME=/dev/snd/pcmC2D0p  
DEVNAME=/dev/snd/pcmC2D0c  
DEVNAME=/dev/input/event19  
DEVNAME=/dev/hidraw4  
DEVNAME=/dev/bus/usb/001/023  
DEVNAME=/dev/snd/pcmC2D0p  
DEVNAME=/dev/hidraw4  
DEVNAME=/dev/snd/pcmC2D0c  
DEVNAME=/dev/input/event19  
DEVNAME=/dev/snd/controlC2

Я выбрал /dev /hidraw4 и когда я вхожу в это

udevadm info --attribute-walk --name /dev/hidraw4

Я получаю следующий вывод:

looking at device '/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.3/0003:046D:0A0B.0018/hidraw/hidraw4':  
*KERNEL=="hidraw4"  
*SUBSYSTEM=="hidraw"  
DRIVER==""  

looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.3/0003:046D:0A0B.0018':  
KERNELS=="0003:046D:0A0B.0018"  
SUBSYSTEMS=="hid"  
DRIVERS=="hid-generic"  

looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.3':  
KERNELS=="1-1:1.3"  
SUBSYSTEMS=="usb"  
DRIVERS=="usbhid"  
ATTRS{bInterfaceClass}=="03"  
ATTRS{bInterfaceSubClass}=="00"  
ATTRS{bInterfaceProtocol}=="00"  
ATTRS{bNumEndpoints}=="01"  
ATTRS{supports_autosuspend}=="1"  
ATTRS{bAlternateSetting}==" 0"  
ATTRS{bInterfaceNumber}=="03"  

looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-1':  
KERNELS=="1-1"  
*SUBSYSTEMS=="usb"  
DRIVERS=="usb"  
ATTRS{bDeviceSubClass}=="00"  
ATTRS{bDeviceProtocol}=="00"  
ATTRS{devpath}=="1"  
ATTRS{idVendor}=="046d"  
ATTRS{speed}=="12"  
ATTRS{bNumInterfaces}==" 4"  
ATTRS{bConfigurationValue}=="1"  
ATTRS{bMaxPacketSize0}=="8"  
ATTRS{busnum}=="1"  
ATTRS{devnum}=="24"  
ATTRS{configuration}=="G8 v3.0.0.0"  
ATTRS{bMaxPower}=="100mA"  
ATTRS{authorized}=="1"  
ATTRS{bmAttributes}=="80"  
ATTRS{bNumConfigurations}=="1"  
ATTRS{maxchild}=="0"  
ATTRS{bcdDevice}=="1013"  
ATTRS{avoid_reset_quirk}=="0"  
ATTRS{quirks}=="0x0"  
ATTRS{version}==" 2.00"  
ATTRS{urbnum}=="661213"  
ATTRS{ltm_capable}=="no"  
*ATTRS{manufacturer}=="Logitech"  
ATTRS{removable}=="unknown"  
ATTRS{idProduct}=="0a0b"  
ATTRS{bDeviceClass}=="00"  
*ATTRS{product}=="Logitech USB Headset"  

looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1':  
KERNELS=="usb1"  
SUBSYSTEMS=="usb"  
DRIVERS=="usb"  
ATTRS{bDeviceSubClass}=="00"  
ATTRS{bDeviceProtocol}=="01"  
ATTRS{devpath}=="0"  
ATTRS{idVendor}=="1d6b"  
ATTRS{speed}=="480"  
ATTRS{bNumInterfaces}==" 1"  
ATTRS{bConfigurationValue}=="1"  
ATTRS{bMaxPacketSize0}=="64"  
ATTRS{authorized_default}=="1"  
ATTRS{busnum}=="1"  
ATTRS{devnum}=="1"  
ATTRS{configuration}==""  
ATTRS{bMaxPower}=="0mA"  
ATTRS{authorized}=="1"  
ATTRS{bmAttributes}=="e0"  
ATTRS{bNumConfigurations}=="1"  
ATTRS{maxchild}=="9"  
ATTRS{bcdDevice}=="0400"  
ATTRS{avoid_reset_quirk}=="0"  
ATTRS{quirks}=="0x0"  
ATTRS{serial}=="0000:00:14.0"  
ATTRS{version}==" 2.00"  
ATTRS{urbnum}=="472"  
ATTRS{ltm_capable}=="no"  
ATTRS{manufacturer}=="Linux 4.0.0-040000-generic xhci-hcd"  
ATTRS{removable}=="unknown"  
ATTRS{idProduct}=="0002"  
ATTRS{bDeviceClass}=="09"  
ATTRS{product}=="xHCI Host Controller"  

looking at parent device '/devices/pci0000:00/0000:00:14.0':  
KERNELS=="0000:00:14.0"  
SUBSYSTEMS=="pci"  
DRIVERS=="xhci_hcd"  
ATTRS{irq}=="40"  
ATTRS{subsystem_vendor}=="0x17aa"  
ATTRS{broken_parity_status}=="0"  
ATTRS{class}=="0x0c0330"  
ATTRS{driver_override}=="(null)"  
ATTRS{consistent_dma_mask_bits}=="64"  
ATTRS{dma_mask_bits}=="64"  
ATTRS{local_cpus}=="0f"  
ATTRS{device}=="0x9c31"  
ATTRS{enable}=="1"  
ATTRS{msi_bus}=="1"  
ATTRS{local_cpulist}=="0-3"  
ATTRS{vendor}=="0x8086"  
ATTRS{subsystem_device}=="0x220c"  
ATTRS{numa_node}=="-1"  
ATTRS{d3cold_allowed}=="1"  

looking at parent device '/devices/pci0000:00':  
KERNELS=="pci0000:00"  
SUBSYSTEMS==""  
DRIVERS==""

Я выбрал значения со звездочкой * для своего правила udev.
Мое полное правило:

KERNEL=="hidraw4", SUBSYSTEM=="hidraw", SUBSYSTEMS=="usb", ATTRS{manufacturer}=="Logitech", ATTRS{product}=="Logitech USB Headset", ACTION=="add", RUN+="/usr/local/bin/run-script-in-background.sh /usr/local/bin/usb-headset-set-default.sh"  

Оба сценария работают, если они введены в терминал, поэтому ошибка должна быть где-то в правиле udev!

0