간단한 udev 규칙을 설정하는 데 문제가 있습니다.
pi@raspberrypi:~ $ ls -l /home/pi/test.sh
-rwxr-xr-x 1 pi pi 37 Jun 25 15:20 /home/pi/test.sh # executable
pi@raspberrypi:~ $ cat /home/pi/test.sh
#!/bin/sh
echo asdf >> /tmp/asdf.txt # this works when run manually, even as root
pi@raspberrypi:~ $ cat /etc/udev/rules.d/10-usb-uart.rules
SUBSYSTEM=="tty", ACTION=="add", ATTRS{idVendor}=="0403", RUN+="/home/pi/test.sh"
나는 ATTRS{idVendor}=="0403"
이것으로부터 얻는다 :
pi@raspberrypi:~ $ sudo udevadm info -a /dev/ttyUSB0
looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB0/tty/ttyUSB0':
KERNEL=="ttyUSB0"
SUBSYSTEM=="tty"
DRIVER==""
looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB0':
KERNELS=="ttyUSB0"
...
ATTRS{port_number}=="0"
looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0':
KERNELS=="1-1.3:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="ftdi_sio"
ATTRS{authorized}=="1"
...
ATTRS{supports_autosuspend}=="1"
looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3':
KERNELS=="1-1.3"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
...
ATTRS{devnum}=="8"
ATTRS{devpath}=="1.3"
ATTRS{devspec}==" (null)"
ATTRS{idProduct}=="6001"
ATTRS{idVendor}=="0403"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="FTDI"
...
그런데 USB 장치를 연결하거나 연결을 끊을 때 파일에 출력이 없습니다.
udevadm test
:
pi@raspberrypi:~ $ udevadm test $(udevadm info -q path -n /dev/ttyUSB0) 2>&1
calling: test
version 232
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: 232
file size: 8788458 bytes
header size 80 bytes
strings 1851626 bytes
nodes 6936752 bytes
Load module index
Found container virtualization none
timestamp of '/etc/systemd/network' changed
timestamp of '/lib/systemd/network' changed
Skipping overridden file: /lib/systemd/network/99-default.link.
Skipping empty file: /etc/systemd/network/99-default.link
Created link configuration context.
timestamp of '/etc/udev/rules.d' changed
Reading rules file: /lib/udev/rules.d/10-local-rpi.rules
Reading rules file: /etc/udev/rules.d/10-usb-uart.rules # my file
Reading rules file: /lib/udev/rules.d/15-i2c-modprobe.rules
Reading rules file: /lib/udev/rules.d/40-scratch.rules
Reading rules file: /lib/udev/rules.d/40-usb_modeswitch.rules
Reading rules file: /lib/udev/rules.d/50-firmware.rules
Reading rules file: /lib/udev/rules.d/50-udev-default.rules
Reading rules file: /lib/udev/rules.d/55-dm.rules
Reading rules file: /lib/udev/rules.d/60-block.rules
Reading rules file: /lib/udev/rules.d/60-bluealsa.rules
Reading rules file: /lib/udev/rules.d/60-cdrom_id.rules
Reading rules file: /lib/udev/rules.d/60-crda.rules
Reading rules file: /lib/udev/rules.d/60-drm.rules
Reading rules file: /lib/udev/rules.d/60-evdev.rules
Reading rules file: /lib/udev/rules.d/60-fuse.rules
Reading rules file: /lib/udev/rules.d/60-i2c-tools.rules
Reading rules file: /lib/udev/rules.d/60-libgphoto2-6.rules
Reading rules file: /lib/udev/rules.d/60-persistent-alsa.rules
Reading rules file: /lib/udev/rules.d/60-persistent-input.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage-dm.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage-tape.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage.rules
Reading rules file: /lib/udev/rules.d/60-persistent-v4l.rules
Reading rules file: /lib/udev/rules.d/60-serial.rules
Reading rules file: /lib/udev/rules.d/60-triggerhappy.rules
Reading rules file: /lib/udev/rules.d/64-btrfs.rules
Reading rules file: /lib/udev/rules.d/64-xorg-xkb.rules
Reading rules file: /lib/udev/rules.d/65-libwacom.rules
Reading rules file: /lib/udev/rules.d/69-libmtp.rules
Reading rules file: /lib/udev/rules.d/70-debian-uaccess.rules
Reading rules file: /lib/udev/rules.d/70-mouse.rules
Reading rules file: /lib/udev/rules.d/70-power-switch.rules
Reading rules file: /lib/udev/rules.d/70-touchpad.rules
Reading rules file: /lib/udev/rules.d/70-uaccess.rules
Reading rules file: /lib/udev/rules.d/71-seat.rules
Reading rules file: /lib/udev/rules.d/73-seat-late.rules
Reading rules file: /lib/udev/rules.d/73-special-net-names.rules
Reading rules file: /lib/udev/rules.d/73-usb-net-by-mac.rules
Reading rules file: /lib/udev/rules.d/75-net-description.rules
Reading rules file: /lib/udev/rules.d/75-probe_mtd.rules
Reading rules file: /lib/udev/rules.d/78-sound-card.rules
Reading rules file: /lib/udev/rules.d/80-debian-compat.rules
Reading rules file: /lib/udev/rules.d/80-drivers.rules
Reading rules file: /lib/udev/rules.d/80-ifupdown.rules
Reading rules file: /lib/udev/rules.d/80-libinput-device-groups.rules
Reading rules file: /lib/udev/rules.d/80-net-setup-link.rules
Reading rules file: /lib/udev/rules.d/80-udisks2.rules
Reading rules file: /lib/udev/rules.d/85-hwclock.rules
Reading rules file: /lib/udev/rules.d/85-regulatory.rules
Reading rules file: /lib/udev/rules.d/90-alsa-restore.rules
Reading rules file: /lib/udev/rules.d/90-console-setup.rules
Reading rules file: /lib/udev/rules.d/90-libinput-model-quirks.rules
Reading rules file: /lib/udev/rules.d/90-pi-bluetooth.rules
Reading rules file: /lib/udev/rules.d/95-wedo.rules
Reading rules file: /lib/udev/rules.d/97-hid2hci.rules
Reading rules file: /etc/udev/rules.d/99-com.rules
Reading rules file: /lib/udev/rules.d/99-systemd.rules
rules contain 196608 bytes tokens (16384 * 12 bytes), 24141 bytes strings
17173 strings (139139 bytes), 14825 de-duplicated (117347 bytes), 2349 trie nodes used
RUN '/home/pi/test.sh' /etc/udev/rules.d/10-usb-uart.rules:1
PROGRAM 'usb_modeswitch --symlink-name /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB0/tty/ttyUSB0 0403 6001 ' /lib/udev/rules.d/40-usb_modeswitch.rules:10
starting 'usb_modeswitch --symlink-name /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB0/tty/ttyUSB0 0403 6001 '
Process 'usb_modeswitch --symlink-name /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB0/tty/ttyUSB0 0403 6001 ' succeeded.
GROUP 20 /lib/udev/rules.d/50-udev-default.rules:26
IMPORT builtin 'usb_id' /lib/udev/rules.d/60-serial.rules:8
/sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0: if_class 255 protocol 0
IMPORT builtin 'hwdb' /lib/udev/rules.d/60-serial.rules:8
IMPORT builtin 'path_id' /lib/udev/rules.d/60-serial.rules:15
LINK 'serial/by-path/platform-3f980000.usb-usb-0:1.3:1.0-port0' /lib/udev/rules.d/60-serial.rules:17
IMPORT builtin skip 'usb_id' /lib/udev/rules.d/60-serial.rules:19
LINK 'serial/by-id/usb-FTDI_TTL232R-3V3_FT98J77X-if00-port0' /lib/udev/rules.d/60-serial.rules:24
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_TTL232R-3V3_FT98J77X-if00-port0'
creating link '/dev/serial/by-id/usb-FTDI_TTL232R-3V3_FT98J77X-if00-port0' to '/dev/ttyUSB0'
preserve already existing symlink '/dev/serial/by-id/usb-FTDI_TTL232R-3V3_FT98J77X-if00-port0' to '../../ttyUSB0'
found 'c188:0' claiming '/run/udev/links/\x2fserial\x2fby-path\x2fplatform-3f980000.usb-usb-0:1.3:1.0-port0'
creating link '/dev/serial/by-path/platform-3f980000.usb-usb-0:1.3:1.0-port0' to '/dev/ttyUSB0'
preserve already existing symlink '/dev/serial/by-path/platform-3f980000.usb-usb-0:1.3:1.0-port0' to '../../ttyUSB0'
.ID_PORT=0
ACTION=add
DEVLINKS=/dev/serial/by-path/platform-3f980000.usb-usb-0:1.3:1.0-port0 /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FT98J77X-if00-port0
DEVNAME=/dev/ttyUSB0
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB0/tty/ttyUSB0
ID_BUS=usb
ID_MODEL=TTL232R-3V3
ID_MODEL_ENC=TTL232R-3V3
ID_MODEL_FROM_DATABASE=FT232 Serial (UART) IC
ID_MODEL_ID=6001
ID_PATH=platform-3f980000.usb-usb-0:1.3:1.0
ID_PATH_TAG=platform-3f980000_usb-usb-0_1_3_1_0
ID_REVISION=0600
ID_SERIAL=FTDI_TTL232R-3V3_FT98J77X
ID_SERIAL_SHORT=FT98J77X
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
TAGS=:systemd:
USEC_INITIALIZED=321019972
run: '/home/pi/test.sh' # That's good!
Unload module index
Unloaded link configuration context.
끝에 "run"이 맞습니다. ACTION
, 그리고 ID_VENDOR_ID
.
따라서 "RUN"은 괜찮아 보이지만 출력이 없습니다 /tmp/asdf.txt
.
udevadm monitor
:
KERNEL[972.728210] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2 (usb)
KERNEL[972.734972] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
KERNEL[972.735197] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0 (usb-serial)
KERNEL[972.736614] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0/tty/ttyUSB0 (tty)
UDEV [972.757922] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2 (usb)
UDEV [972.765063] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
UDEV [972.770564] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0 (usb-serial)
UDEV [972.798201] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0/tty/ttyUSB0 (tty)
그리고 udevadm monitor --property
:
UDEV [1280.772278] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0/tty/ttyUSB0 (tty)
.ID_PORT=0
ACTION=add
DEVLINKS=/dev/serial/by-path/platform-3f980000.usb-usb-0:1.2:1.0-port0 /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FT98J77X-if00-port0
DEVNAME=/dev/ttyUSB0
DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0/tty/ttyUSB0
ID_BUS=usb
ID_MODEL=TTL232R-3V3
ID_MODEL_ENC=TTL232R-3V3
ID_MODEL_FROM_DATABASE=FT232 Serial (UART) IC
ID_MODEL_ID=6001
ID_PATH=platform-3f980000.usb-usb-0:1.2:1.0
ID_PATH_TAG=platform-3f980000_usb-usb-0_1_2_1_0
ID_REVISION=0600
ID_SERIAL=FTDI_TTL232R-3V3_FT98J77X
ID_SERIAL_SHORT=FT98J77X
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
SEQNUM=3895
SUBSYSTEM=tty
TAGS=:systemd:
USEC_INITIALIZED=1280765243
여기에는 "RUN"이 없습니다.
udevadm monitor --property
출력은 계속 표시됩니다. 하지만 "RUN" 필드는 없습니다. 거기에 있을 것이라고 기대해야 할지 모르겠습니다. udevadm test
보여줬는데, 그렇지 udevadm monitor --property
않아서 놀랐어요.
이름을 no av로 10-usb-uart.rules
변경해 보았습니다 .98-usb-uart.rules
나는 가지고있다추가해 보세요 , OPTIONS="last_rule"
로 시작하는 파일에는 10-
av가 없습니다.
udevadm monitor --property
지금처럼 디스플레이를 기대해도 될까요 ?run
udevadm test
무슨 일이 일어나고 있는지 디버깅하기 위해 또 무엇을 할 수 있나요?
답변1
스크립트 내용 /home/pi/test.sh
이 문제입니다.
가 있지만 #!/bin/sh
내장 명령이 echo
실패합니다.
그것을 작품으로 바꾸십시오 /bin/echo
:
$ cat /home/pi/test.sh
#!/bin/sh
/bin/echo asdf >> /tmp/asdf.txt
특히 인터프리터를 지정한 후에 내장 함수가 작동하지 않는 이유가 무엇인지 잘 모르겠습니다. 이것은 문제인 것처럼 보이지만 sh
아니요 bash
, 이것도 작동합니다.
$ cat /home/pi/test.sh
#!/bin/bash
echo asdf >> /tmp/asdf.txt
참고로, udevadm monitor --property
표시되지 않는 것 같아 RUN
아쉽습니다.