Udev
udev規則未設置組
我正在嘗試編寫一個 udev 規則來更改我的 MSP-FET430UIF USB 程式器上的組。這是我到目前為止所擁有的(文件名
/etc/udev/rules.d/40-ti-fet430.rules
):SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="f430", MODE="0660", GROUP="plugdev", RUN+="/tmp/test.sh"
執行命令(只是將日期重定向到 /tmp/test)正在工作。但是,/dev/ttyUSB0 設備的組和權限沒有改變:
$ ls -l /dev/ttyUSB0 crw------- 1 root root 188, 0 May 18 13:05 /dev/ttyUSB0
這是的輸出
udevadm test /device/blabla
:$ udevadm test `udevadm info -q path -n /dev/ttyUSB0 ` calling: test version 216 This program is for debugging only, it does not run any program specified by a RUN key. It may show incorrect results, because some values may be different, or not available at a simulation run. load module index timestamp of '/etc/systemd/network' changed timestamp of '/lib/systemd/network' changed Parsed configuration file /lib64/systemd/network/99-default.link Created link configuration context. timestamp of '/etc/udev/rules.d' changed Reading rules file: /lib64/udev/rules.d/40-gentoo.rules Reading rules file: /etc/udev/rules.d/40-ti-fet430.rules Reading rules file: /lib64/udev/rules.d/42-usb-hid-pm.rules Reading rules file: /lib64/udev/rules.d/50-firmware.rules Reading rules file: /lib64/udev/rules.d/50-udev-default.rules Reading rules file: /etc/udev/rules.d/52-digilent-usb.rules Reading rules file: /lib64/udev/rules.d/56-hpmud.rules Reading rules file: /lib64/udev/rules.d/60-cdrom_id.rules Reading rules file: /lib64/udev/rules.d/60-drm.rules Reading rules file: /lib64/udev/rules.d/60-keyboard.rules Reading rules file: /lib64/udev/rules.d/60-persistent-alsa.rules Reading rules file: /lib64/udev/rules.d/60-persistent-input.rules Reading rules file: /lib64/udev/rules.d/60-persistent-serial.rules Reading rules file: /lib64/udev/rules.d/60-persistent-storage-tape.rules Reading rules file: /lib64/udev/rules.d/60-persistent-storage.rules Reading rules file: /lib64/udev/rules.d/60-persistent-v4l.rules Reading rules file: /lib64/udev/rules.d/61-accelerometer.rules Reading rules file: /run/udev/rules.d/61-dev-root-link.rules Reading rules file: /lib64/udev/rules.d/64-btrfs.rules Reading rules file: /lib64/udev/rules.d/70-udev-acl.rules Reading rules file: /lib64/udev/rules.d/75-net-description.rules Reading rules file: /lib64/udev/rules.d/75-probe_mtd.rules Reading rules file: /lib64/udev/rules.d/75-tty-description.rules Reading rules file: /lib64/udev/rules.d/78-sound-card.rules Reading rules file: /lib64/udev/rules.d/80-drivers.rules Reading rules file: /lib64/udev/rules.d/80-net-setup-link.rules Reading rules file: /lib64/udev/rules.d/80-udisks2.rules Reading rules file: /lib64/udev/rules.d/85-regulatory.rules Reading rules file: /lib64/udev/rules.d/90-alsa-restore.rules Reading rules file: /lib64/udev/rules.d/90-network.rules Reading rules file: /lib64/udev/rules.d/95-udev-late.rules Reading rules file: /lib64/udev/rules.d/95-upower-battery-recall-dell.rules Reading rules file: /lib64/udev/rules.d/95-upower-battery-recall-fujitsu.rules Reading rules file: /lib64/udev/rules.d/95-upower-battery-recall-gateway.rules Reading rules file: /lib64/udev/rules.d/95-upower-battery-recall-ibm.rules Reading rules file: /lib64/udev/rules.d/95-upower-battery-recall-lenovo.rules Reading rules file: /lib64/udev/rules.d/95-upower-battery-recall-toshiba.rules Reading rules file: /lib64/udev/rules.d/95-upower-csr.rules Reading rules file: /lib64/udev/rules.d/95-upower-hid.rules Reading rules file: /lib64/udev/rules.d/95-upower-wup.rules Reading rules file: /lib64/udev/rules.d/97-hid2hci.rules rules contain 49152 bytes tokens (4096 * 12 bytes), 12512 bytes strings 2501 strings (28205 bytes), 1749 de-duplicated (16446 bytes), 753 trie nodes used IMPORT builtin 'path_id' /lib64/udev/rules.d/60-persistent-serial.rules:9 LINK 'serial/by-path/pci-0000:00:13.0-usb-0:2:2.0-port0' /lib64/udev/rules.d/60-persistent-serial.rules:11 IMPORT builtin 'usb_id' /lib64/udev/rules.d/60-persistent-serial.rules:13 /sys/devices/pci0000:00/0000:00:13.0/usb2/2-2/2-2:2.0: if_class 255 protocol 0 LINK 'serial/by-id/usb-Texas_Instruments_MSP-FET430UIF_JTAG_Tool_TUSB3410172ECD5EF754FF89-if00-port0' /lib64/udev/rules.d/60-persistent-serial.rules:18 IMPORT builtin skip 'usb_id' /lib64/udev/rules.d/75-tty-description.rules:6 IMPORT builtin 'hwdb' /lib64/udev/rules.d/75-tty-description.rules:6 handling device node '/dev/ttyUSB0', devnum=c188:0, mode=0600, uid=0, gid=0 preserve permissions /dev/ttyUSB0, 020600, uid=0, gid=0 preserve already existing symlink '/dev/char/188:0' to '../ttyUSB0' found 'c188:0' claiming '/run/udev/links//serial/by-id/usb-Texas_Instruments_MSP-FET430UIF_JTAG_Tool_TUSB3410172ECD5EF754FF89-if00-port0' creating link '/dev/serial/by-id/usb-Texas_Instruments_MSP-FET430UIF_JTAG_Tool_TUSB3410172ECD5EF754FF89-if00-port0' to '/dev/ttyUSB0' preserve already existing symlink '/dev/serial/by-id/usb-Texas_Instruments_MSP-FET430UIF_JTAG_Tool_TUSB3410172ECD5EF754FF89-if00-port0' to '../../ttyUSB0' found 'c188:0' claiming '/run/udev/links//serial/by-path/pci-0000:00:13.0-usb-0:2:2.0-port0' creating link '/dev/serial/by-path/pci-0000:00:13.0-usb-0:2:2.0-port0' to '/dev/ttyUSB0' preserve already existing symlink '/dev/serial/by-path/pci-0000:00:13.0-usb-0:2:2.0-port0' to '../../ttyUSB0' unable to create temporary db file '/run/udev/data/c188:0.tmp': Permission denied .ID_PORT=0 ACTION=add DEVLINKS=/dev/serial/by-id/usb-Texas_Instruments_MSP-FET430UIF_JTAG_Tool_TUSB3410172ECD5EF754FF89-if00-port0 /dev/serial/by-path/pci-0000:00:13.0-usb-0:2:2.0-port0 DEVNAME=/dev/ttyUSB0 DEVPATH=/devices/pci0000:00/0000:00:13.0/usb2/2-2/2-2:2.0/ttyUSB0/tty/ttyUSB0 ID_BUS=usb ID_MODEL=MSP-FET430UIF_JTAG_Tool ID_MODEL_ENC=MSP-FET430UIF JTAG Tool ID_MODEL_FROM_DATABASE=MSP-FET430UIF JTAG Tool ID_MODEL_ID=f430 ID_PATH=pci-0000:00:13.0-usb-0:2:2.0 ID_PATH_TAG=pci-0000_00_13_0-usb-0_2_2_0 ID_REVISION=0101 ID_SERIAL=Texas_Instruments_MSP-FET430UIF_JTAG_Tool_TUSB3410172ECD5EF754FF89 ID_SERIAL_SHORT=TUSB3410172ECD5EF754FF89 ID_TYPE=generic ID_USB_CLASS_FROM_DATABASE=Vendor Specific Class ID_USB_DRIVER=ti_usb_3410_5052 ID_USB_INTERFACES=:ff0000: ID_USB_INTERFACE_NUM=00 ID_VENDOR=Texas_Instruments ID_VENDOR_ENC=Texas Instruments ID_VENDOR_FROM_DATABASE=Texas Instruments, Inc. ID_VENDOR_ID=0451 MAJOR=188 MINOR=0 SUBSYSTEM=tty USEC_INITIALIZED=33057949 unload module index Unloaded link configuration context.
(我不得不承認我不確定我應該在
udevadm test
輸出中看到什麼)。總之,為什麼組沒有改變?
PS 有一條規則將組設置為 uucp,但為了簡單起見,我註釋掉了該規則。它在
/lib64/udev/rules.d/50-udev-default.rules
文件中,所以如果我理解正確,我的規則無論如何都會優先。輸出
udevadm info -a /dev/ttyUSB0
:Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the attributes of the device and the attributes from one single parent device. looking at device '/devices/pci0000:00/0000:00:13.0/usb2/2-2/2-2:2.0/ttyUSB0/tty/ttyUSB0': KERNEL=="ttyUSB0" SUBSYSTEM=="tty" DRIVER=="" looking at parent device '/devices/pci0000:00/0000:00:13.0/usb2/2-2/2-2:2.0/ttyUSB0': KERNELS=="ttyUSB0" SUBSYSTEMS=="usb-serial" DRIVERS=="ti_usb_3410_5052_1" ATTRS{port_number}=="0" looking at parent device '/devices/pci0000:00/0000:00:13.0/usb2/2-2/2-2:2.0': KERNELS=="2-2:2.0" SUBSYSTEMS=="usb" DRIVERS=="ti_usb_3410_5052" ATTRS{bInterfaceClass}=="ff" ATTRS{bInterfaceSubClass}=="00" ATTRS{bInterfaceProtocol}=="00" ATTRS{bNumEndpoints}=="03" ATTRS{supports_autosuspend}=="1" ATTRS{bAlternateSetting}==" 0" ATTRS{bInterfaceNumber}=="00" looking at parent device '/devices/pci0000:00/0000:00:13.0/usb2/2-2': KERNELS=="2-2" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{bDeviceSubClass}=="00" ATTRS{bDeviceProtocol}=="00" ATTRS{devpath}=="2" ATTRS{idVendor}=="0451" ATTRS{speed}=="12" ATTRS{bNumInterfaces}==" 1" ATTRS{bConfigurationValue}=="2" ATTRS{bMaxPacketSize0}=="8" ATTRS{busnum}=="2" ATTRS{devnum}=="3" ATTRS{configuration}=="" ATTRS{bMaxPower}=="100mA" ATTRS{authorized}=="1" ATTRS{bmAttributes}=="a0" ATTRS{bNumConfigurations}=="2" ATTRS{maxchild}=="0" ATTRS{bcdDevice}=="0101" ATTRS{avoid_reset_quirk}=="0" ATTRS{quirks}=="0x0" ATTRS{serial}=="TUSB3410172ECD5EF754FF89" ATTRS{version}==" 1.10" ATTRS{urbnum}=="13" ATTRS{ltm_capable}=="no" ATTRS{manufacturer}=="Texas Instruments" ATTRS{removable}=="unknown" ATTRS{idProduct}=="f430" ATTRS{bDeviceClass}=="ff" ATTRS{product}=="MSP-FET430UIF JTAG Tool" looking at parent device '/devices/pci0000:00/0000:00:13.0/usb2': KERNELS=="usb2" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{bDeviceSubClass}=="00" ATTRS{bDeviceProtocol}=="00" ATTRS{devpath}=="0" ATTRS{idVendor}=="1d6b" ATTRS{speed}=="12" ATTRS{bNumInterfaces}==" 1" ATTRS{bConfigurationValue}=="1" ATTRS{bMaxPacketSize0}=="64" ATTRS{authorized_default}=="1" ATTRS{busnum}=="2" ATTRS{devnum}=="1" ATTRS{configuration}=="" ATTRS{bMaxPower}=="0mA" ATTRS{authorized}=="1" ATTRS{bmAttributes}=="e0" ATTRS{bNumConfigurations}=="1" ATTRS{maxchild}=="2" ATTRS{bcdDevice}=="0318" ATTRS{avoid_reset_quirk}=="0" ATTRS{quirks}=="0x0" ATTRS{serial}=="0000:00:13.0" ATTRS{version}==" 1.10" ATTRS{urbnum}=="49" ATTRS{ltm_capable}=="no" ATTRS{manufacturer}=="Linux 3.18.12-gentoo ohci_hcd" ATTRS{removable}=="unknown" ATTRS{idProduct}=="0001" ATTRS{bDeviceClass}=="09" ATTRS{product}=="OHCI PCI host controller" looking at parent device '/devices/pci0000:00/0000:00:13.0': KERNELS=="0000:00:13.0" SUBSYSTEMS=="pci" DRIVERS=="ohci-pci" ATTRS{irq}=="16" ATTRS{subsystem_vendor}=="0x1028" ATTRS{broken_parity_status}=="0" ATTRS{class}=="0x0c0310" ATTRS{driver_override}=="(null)" ATTRS{consistent_dma_mask_bits}=="32" ATTRS{dma_mask_bits}=="32" ATTRS{local_cpus}=="ffffffff" ATTRS{device}=="0x4387" ATTRS{enable}=="1" ATTRS{msi_bus}=="1" ATTRS{local_cpulist}=="0-31" ATTRS{vendor}=="0x1002" ATTRS{subsystem_device}=="0x01fc" looking at parent device '/devices/pci0000:00': KERNELS=="pci0000:00" SUBSYSTEMS=="" DRIVERS==""
- 您定位錯誤的節點。您目前的規則:
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="f430"
匹配此節點:
/devices/pci0000:00/0000:00:13.0/usb2/2-2
- 您應該在哪裡定位與您的設備匹配的葉節點,
/dev/ttyUSB0
即:/devices/pci0000:00/0000:00:13.0/usb2/2-2/2-2:2.0/ttyUSB0/tty/ttyUSB0
或許:
/devices/pci0000:00/0000:00:13.0/usb2/2-2/2-2:2.0/ttyUSB0
試試這個:
KERNEL=="ttyUSB[0-9]*", SUBSYSTEMS=="usb", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="f430", MODE="0660", GROUP="plugdev", RUN+="/tmp/test.sh"
SUBSYSTEMS
注意,ATTRS
和SUBSYSTEM
,之間的區別ATTR
。查看man udev
- 好吧,你的新規則:
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="f430", MODE="0660", GROUP="plugdev", RUN+="/tmp/test.sh"
將為所有這些節點觸發:
/devices/pci0000:00/0000:00:13.0/usb2/2-2 /devices/pci0000:00/0000:00:13.0/usb2/2-2/2-2:2.0 /devices/pci0000:00/0000:00:13.0/usb2/2-2/2-2:2.0/ttyUSB0 /devices/pci0000:00/0000:00:13.0/usb2/2-2/2-2:2.0/ttyUSB0/tty/ttyUSB0