udev规则适用于`udevadm test`,但不适用于`udevadm trigger`

时间:2015-04-11 01:50:43

标签: ubuntu udev

我有一个基于this question创建的4端口USB转RS232集线器的udev规则:

SUBSYSTEMS=="usb", DRIVERS=="usb", ATTRS{serial}=="A4018BU0", SYMLINK+="ttyLumagen"

它没有按预期创建符号链接,所以debug我尝试了udevadm test它似乎有效:

% sudo udevadm info --query=path --name=/dev/ttyUSB0
/devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.1/3-9.1:1.0/ttyUSB0/tty/ttyUSB0
% sudo udevadm test /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.1/3-9.1:1.0/ttyUSB0/tty/ttyUSB0
calling: test
version 204
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.

=== trie on-disk ===
tool version:          204
file size:         5661386 bytes
header size             80 bytes
strings            1265626 bytes
nodes              4395680 bytes
load module index
read rules file: /lib/udev/rules.d/40-crda.rules
read rules file: /lib/udev/rules.d/40-gnupg.rules
read rules file: /lib/udev/rules.d/40-hyperv-hotadd.rules
read rules file: /lib/udev/rules.d/42-usb-hid-pm.rules
read rules file: /lib/udev/rules.d/50-firmware.rules
read rules file: /lib/udev/rules.d/50-udev-default.rules
read rules file: /lib/udev/rules.d/55-dm.rules
read rules file: /lib/udev/rules.d/60-cdrom_id.rules
read rules file: /lib/udev/rules.d/60-keyboard.rules
read rules file: /lib/udev/rules.d/60-persistent-alsa.rules
read rules file: /lib/udev/rules.d/60-persistent-input.rules
read rules file: /lib/udev/rules.d/60-persistent-serial.rules
read rules file: /lib/udev/rules.d/60-persistent-storage-dm.rules
read rules file: /lib/udev/rules.d/60-persistent-storage-tape.rules
read rules file: /lib/udev/rules.d/60-persistent-storage.rules
read rules file: /lib/udev/rules.d/60-persistent-v4l.rules
read rules file: /lib/udev/rules.d/60-zvol.rules
read rules file: /lib/udev/rules.d/61-accelerometer.rules
read rules file: /lib/udev/rules.d/64-btrfs.rules
read rules file: /lib/udev/rules.d/64-md-raid.rules
read rules file: /lib/udev/rules.d/69-vdev.rules
read rules file: /lib/udev/rules.d/70-power-switch.rules
read rules file: /lib/udev/rules.d/70-uaccess.rules
read rules file: /lib/udev/rules.d/71-biosdevname.rules
read rules file: /lib/udev/rules.d/71-seat.rules
read rules file: /lib/udev/rules.d/73-idrac.rules
read rules file: /lib/udev/rules.d/73-seat-late.rules
read rules file: /lib/udev/rules.d/75-net-description.rules
read rules file: /lib/udev/rules.d/75-persistent-net-generator.rules
read rules file: /lib/udev/rules.d/75-probe_mtd.rules
read rules file: /lib/udev/rules.d/75-tty-description.rules
read rules file: /lib/udev/rules.d/78-graphics-card.rules
read rules file: /lib/udev/rules.d/78-sound-card.rules
read rules file: /lib/udev/rules.d/80-drivers.rules
read rules file: /lib/udev/rules.d/85-hdparm.rules
read rules file: /lib/udev/rules.d/85-keyboard-configuration.rules
read rules file: /lib/udev/rules.d/85-regulatory.rules
read rules file: /lib/udev/rules.d/95-udev-late.rules
read rules file: /etc/udev/rules.d/flirc.rules
read rules file: /etc/udev/rules.d/serialports.rules
read rules file: /etc/udev/rules.d/tivoslide.rules
rules contain 24576 bytes tokens (2048 * 12 bytes), 12172 bytes strings
1941 strings (23630 bytes), 1266 de-duplicated (12134 bytes), 676 trie nodes used
GROUP 20 /lib/udev/rules.d/50-udev-default.rules:19
IMPORT builtin 'path_id' /lib/udev/rules.d/60-persistent-serial.rules:9
LINK 'serial/by-path/pci-0000:00:14.0-usb-0:9.1:1.0-port0' /lib/udev/rules.d/60-persistent-serial.rules:11
IMPORT builtin 'usb_id' /lib/udev/rules.d/60-persistent-serial.rules:13
/sys/devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.1/3-9.1:1.0: if_class 255 protocol 0
LINK 'serial/by-id/usb-FTDI_FT232R_USB_UART_A4018BU0-if00-port0' /lib/udev/rules.d/60-persistent-serial.rules:18
IMPORT builtin skip 'usb_id' /lib/udev/rules.d/75-tty-description.rules:6
IMPORT builtin 'hwdb' /lib/udev/rules.d/75-tty-description.rules:6
LINK 'ttyLumagen' /etc/udev/rules.d/serialports.rules:2
handling device node '/dev/ttyUSB0', devnum=c188:0, mode=0660, uid=0, gid=20
preserve permissions /dev/ttyUSB0, 020660, uid=0, gid=20
preserve already existing symlink '/dev/char/188:0' to '../ttyUSB0'
found 'c188:0' claiming '/run/udev/links/\x2fserial\x2fby-id\x2fusb-FTDI_FT232R_USB_UART_A4018BU0-if00-port0'
creating link '/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A4018BU0-if00-port0' to '/dev/ttyUSB0'
preserve already existing symlink '/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A4018BU0-if00-port0' to '../../ttyUSB0'
found 'c188:0' claiming '/run/udev/links/\x2fserial\x2fby-path\x2fpci-0000:00:14.0-usb-0:9.1:1.0-port0'
creating link '/dev/serial/by-path/pci-0000:00:14.0-usb-0:9.1:1.0-port0' to '/dev/ttyUSB0'
preserve already existing symlink '/dev/serial/by-path/pci-0000:00:14.0-usb-0:9.1:1.0-port0' to '../../ttyUSB0'
creating link '/dev/ttyLumagen' to '/dev/ttyUSB0'
creating symlink '/dev/ttyLumagen' to 'ttyUSB0'
.ID_PORT=0
ACTION=add
DEVLINKS=/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A4018BU0-if00-port0 /dev/serial/by-path/pci-0000:00:14.0-usb-0:9.1:1.0-port0 /dev/ttyLumagen
DEVNAME=/dev/ttyUSB0
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.1/3-9.1:1.0/ttyUSB0/tty/ttyUSB0
ID_BUS=usb
ID_MODEL=FT232R_USB_UART
ID_MODEL_ENC=FT232R\x20USB\x20UART
ID_MODEL_FROM_DATABASE=FT232 USB-Serial (UART) IC
ID_MODEL_ID=6001
ID_PATH=pci-0000:00:14.0-usb-0:9.1:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_9_1_1_0
ID_REVISION=0600
ID_SERIAL=FTDI_FT232R_USB_UART_A4018BU0
ID_SERIAL_SHORT=A4018BU0
ID_TYPE=generic
ID_USB_DRIVER=ftdi_sio
ID_USB_INTERFACES=:ffffff:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=FTDI
ID_VENDOR_ENC=FTDI
ID_VENDOR_FROM_DATABASE=Future Technology Devices International, Ltd
ID_VENDOR_ID=0403
MAJOR=188
MINOR=0
SUBSYSTEM=tty
USEC_INITIALIZED=426370555
unload module index

符号链接确实是按预期创建的。然后我运行了udevadm trigger,它删除了符号链接。

为什么udevadm trigger(以及正常的udev操作)不起作用,但udevadm test有效?

系统是Ubuntu服务器14.04 LTS:Linux jimmy 3.13.0-40-generic #69-Ubuntu SMP Thu Nov 13 17:53:56 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

2 个答案:

答案 0 :(得分:1)

我知道这是旧的af,但是我会将其留给像我这样的未来搜索者使用

检查您的规则是否包含常规的ACTION=="add"。似乎udevadm trigger会将其处理视为change操作,因此带有此子句的任何规则都不匹配。 udevadm test确实使用add动作,这就是它在那里起作用的原因。由于它也是add操作,因此它也应该在正常的启动设置下工作。

答案 1 :(得分:0)

我有完全一样的现象。 udevadm test有效,但udevadm trigger无效。我的情况是udevd没有运行。我刚刚输入了udevd &,然后将规则应用于了udevadm trigger