You are not logged in.
Hi!
I am trying to write an udev rule to detect if an usb audio device was plugged / unplugged to change my default audio device (in effect this udev rule should run a bash script..).
Right now it looks like that:
KERNEL=="pcmC[D0-9cp]*", DRIVERS=="usb", ACTION=="add", PROGRAM="/bin/bash -c '/home/me/dotfiles/soundconf.sh attached'"and I have a second rule for "remove" instead of add calling a different parameter.
However, unfortunately the change is not being detected. my sound devices are listed in e.g. /proc/asound/card0/pcm0c etc for my first card and /proc/asound/card4/... for the second.
They are also listed in /proc/asound/NAMEOFCARD (e.g. PCH).
how can i reliably detect if one was plugged or unplugged?
thanks
!
Last edited by replax (2013-11-27 22:50:00)
Offline
Hello
To execute a program, you need to use 'RUN+=' not 'PROGRAM=' (read 'man udev').
and 'KERNEL=="pcmC[D0-9cp]*' will match 'pcmC' followed by one of the characters in the brackets, followed by zero or more characters:
is this what you want?
Last edited by berbae (2013-11-24 10:25:28)
Offline
hi berbae,
thanks!!
changed the program= to run+= and the regex as well, to match my audio interface names.
still not getting picked up, think my regex is wrong now, actually.
will 'KERNEL=="pcm[0-9cp]*' pick up devices like: pcm0c, pcm7p?
cheers!
Offline
There is a double quote missing after the * sign. And run+= should be uppercase: RUN+=
Try KERNEL=="pcm[0-9][cp]"
if the device name is 'pcm' followed by one digit only, then followed by 'c' or 'p'.
KERNEL=="pcm[0-9][0-9]*[cp]"
if the device name is 'pcm' followed by possibly several digits, then followed by 'c' or 'p'.
KERNEL=="pcm[0-9][0-9]*[cp]*"
if the device name is 'pcm' followed by possibly several digits, and 'c' or 'p' or nothing.
See Falconindy's post
Last edited by berbae (2013-11-23 21:53:19)
Offline
Point of clarification -- udev rules do not match on on regular expressions, but globs (specifically, the implementation uses fnmatch). The expression "pcm[0-9cp]*" matches the string "pcm", followed by a single number or the letters "c" or "p", and then 0 to many characters.
Offline
Thanks Falconindy
I mixed up regular expressions and glob pattern matching (I don't write udev rules).
But KERNEL=="pcm[0-9][cp]" should be correct if there is only one digit followed with 'c' or 'p'.
Offline
thanks for all the help!
however, for some reason the connect/disconnect event is still not being picked up.
I think it might have something to do with the naming of my soundcards..
in /proc/asound/ there are two folders for each sound device. one of the two folders is a symlink and named like the audio device name, eg USB Audio or ThinkPadEC. The folder it symlinks to is called card0 or card1 etc.
inside each card[0-9] folder is another folder which is pcm0c or pcm3p etc.
I think that the pcm folders are related to each channel of each sound card. e.g. front channel, rear channel etc while the top folder is referring to the card itself.
would I need to refer to the card itself?
thanks a lot!
Offline
Before writing the udev rule, try to observe what happens when you plug the USB audio devices in, running:
udevadm monitor --kernel
and post the changes after the plugging in of the audio device.
Do the same again running:
udevadm monitor --udev --property
post the output when you plug in the device.
Last edited by berbae (2013-11-24 10:59:00)
Offline
hi!
thanks!
my output for "sudo udevadm monitor --kernel" is:
monitor will print the received events for:
KERNEL - the kernel uevent
KERNEL[409.000749] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input24/event18 (input)
KERNEL[409.023556] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input24 (input)
KERNEL[409.023611] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0005/hidraw/hidraw0 (hidraw)
KERNEL[409.023632] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0005 (hid)
KERNEL[409.023648] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0 (usb)
KERNEL[409.023829] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D1p (sound)
KERNEL[409.023845] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D0p (sound)
KERNEL[409.023859] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/controlC1 (sound)
KERNEL[409.023869] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1 (sound)
KERNEL[409.023885] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1 (usb)
KERNEL[409.023899] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.3 (usb)
KERNEL[409.024517] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1 (usb)
KERNEL[411.633928] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1 (usb)
KERNEL[411.634043] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0 (usb)
KERNEL[411.648482] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0006 (hid)
KERNEL[411.649170] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input25 (input)
KERNEL[411.649320] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input25/event18 (input)
KERNEL[411.649347] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0006/hidraw/hidraw0 (hidraw)
KERNEL[411.657385] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1 (usb)
KERNEL[411.680527] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1 (sound)
KERNEL[411.680564] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D1p (sound)
KERNEL[411.680737] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D0p (sound)
KERNEL[411.680796] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/controlC1 (sound)
KERNEL[411.680951] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.3 (usb)
KERNEL[411.705251] change /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1 (sound)and my output for "sudo udevadm --udev --property" is:
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
UDEV [409.001439] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input24/event18 (
input)
ACTION=remove
DEVLINKS=/dev/input/by-id/usb-HiFimeDIY_Audio_SA9023_USB_Audio-event-if00 /dev/input/by-path/pci-0000:00:1d.0-usb-0:1.2
.1:1.0-event
DEVNAME=/dev/input/event18
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input24/event18
ID_BUS=usb
ID_INPUT=1
ID_MODEL=SA9023_USB_Audio
ID_MODEL_ENC=SA9023\x20USB\x20Audio
ID_MODEL_ID=10e1
ID_PATH=pci-0000:00:1d.0-usb-0:1.2.1:1.0
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_2_1_1_0
ID_REVISION=0001
ID_SERIAL=HiFimeDIY_Audio_SA9023_USB_Audio
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030000:010100:010200:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=HiFimeDIY_Audio
ID_VENDOR_ENC=HiFimeDIY\x20Audio
ID_VENDOR_ID=262a
MAJOR=13
MINOR=82
SEQNUM=2036
SUBSYSTEM=input
USEC_INITIALIZED=4690
UDEV [409.024376] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input24 (input)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input24
EV=1
ID_BUS=usb
ID_FOR_SEAT=input-pci-0000_00_1d_0-usb-0_1_2_1_1_0
ID_INPUT=1
ID_MODEL=SA9023_USB_Audio
ID_MODEL_ENC=SA9023\x20USB\x20Audio
ID_MODEL_ID=10e1
ID_PATH=pci-0000:00:1d.0-usb-0:1.2.1:1.0
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_2_1_1_0
ID_REVISION=0001
ID_SERIAL=HiFimeDIY_Audio_SA9023_USB_Audio
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030000:010100:010200:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=HiFimeDIY_Audio
ID_VENDOR_ENC=HiFimeDIY\x20Audio
ID_VENDOR_ID=262a
MODALIAS=input:b0003v262Ap10E1e0100-e0,kramlsfw
NAME="HiFimeDIY Audio SA9023 USB Audio"
PHYS="usb-0000:00:1d.0-1.2.1/input0"
PRODUCT=3/262a/10e1/100
PROP=0
SEQNUM=2037
SUBSYSTEM=input
TAGS=:seat:
UNIQ=""
USEC_INITIALIZED=634532
UDEV [409.024487] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0005/hid
raw/hidraw0 (hidraw)
ACTION=remove
DEVNAME=/dev/hidraw0
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0005/hidraw/hidraw0
MAJOR=248
MINOR=0
SEQNUM=2038
SUBSYSTEM=hidraw
USEC_INITIALIZED=9023681
UDEV [409.026487] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0005 (hi
d)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0005
HID_ID=0003:0000262A:000010E1
HID_NAME=HiFimeDIY Audio SA9023 USB Audio
HID_PHYS=usb-0000:00:1d.0-1.2.1/input0
MODALIAS=hid:b0003g0001v0000262Ap000010E1
SEQNUM=2039
SUBSYSTEM=hid
USEC_INITIALIZED=23875
UDEV [409.026531] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/controlC1 (
sound)
ACTION=remove
DEVLINKS=/dev/snd/by-id/usb-HiFimeDIY_Audio_SA9023_USB_Audio-01 /dev/snd/by-path/pci-0000:00:1d.0-usb-0:1.2.1:1.1
DEVNAME=/dev/snd/controlC1
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/controlC1
ID_BUS=usb
ID_MODEL=SA9023_USB_Audio
ID_MODEL_ENC=SA9023\x20USB\x20Audio
ID_MODEL_ID=10e1
ID_PATH=pci-0000:00:1d.0-usb-0:1.2.1:1.1
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_2_1_1_1
ID_REVISION=0001
ID_SERIAL=HiFimeDIY_Audio_SA9023_USB_Audio
ID_TYPE=audio
ID_USB_DRIVER=snd-usb-audio
ID_USB_INTERFACES=:030000:010100:010200:
ID_USB_INTERFACE_NUM=01
ID_VENDOR=HiFimeDIY_Audio
ID_VENDOR_ENC=HiFimeDIY\x20Audio
ID_VENDOR_ID=262a
MAJOR=116
MINOR=13
SEQNUM=2043
SUBSYSTEM=sound
TAGS=:uaccess:
USEC_INITIALIZED=665890
UDEV [409.026557] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.3 (usb)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.3
DEVTYPE=usb_interface
ID_MODEL_FROM_DATABASE=USB-2.0 4-Port HUB
ID_VENDOR_FROM_DATABASE=Genesys Logic, Inc.
INTERFACE=1/2/0
MODALIAS=usb:v262Ap10E1d0001dc00dsc00dp00ic01isc02ip00in03
PRODUCT=262a/10e1/1
SEQNUM=2046
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=665944
UDEV [409.026573] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0 (usb)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0
DEVTYPE=usb_interface
ID_MODEL_FROM_DATABASE=USB-2.0 4-Port HUB
ID_VENDOR_FROM_DATABASE=Genesys Logic, Inc.
INTERFACE=3/0/0
MODALIAS=usb:v262Ap10E1d0001dc00dsc00dp00ic03isc00ip00in00
PRODUCT=262a/10e1/1
SEQNUM=2040
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=130
UDEV [409.026616] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D0p (s
ound)
ACTION=remove
DEVNAME=/dev/snd/pcmC1D0p
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D0p
MAJOR=116
MINOR=12
SEQNUM=2042
SUBSYSTEM=sound
TAGS=:uaccess:
USEC_INITIALIZED=5836
UDEV [409.078843] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D1p (s
ound)
ACTION=remove
DEVNAME=/dev/snd/pcmC1D1p
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D1p
MAJOR=116
MINOR=11
SEQNUM=2041
SUBSYSTEM=sound
TAGS=:uaccess:
USEC_INITIALIZED=5794
UDEV [409.079039] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1 (sound)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1
ID_BUS=usb
ID_FOR_SEAT=sound-pci-0000_00_1d_0-usb-0_1_2_1_1_1
ID_ID=usb-HiFimeDIY_Audio_SA9023_USB_Audio-01-Audio
ID_MODEL=SA9023_USB_Audio
ID_MODEL_ENC=SA9023\x20USB\x20Audio
ID_MODEL_FROM_DATABASE=USB-2.0 4-Port HUB
ID_MODEL_ID=10e1
ID_PATH=pci-0000:00:1d.0-usb-0:1.2.1:1.1
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_2_1_1_1
ID_REVISION=0001
ID_SERIAL=HiFimeDIY_Audio_SA9023_USB_Audio
ID_TYPE=audio
ID_USB_DRIVER=snd-usb-audio
ID_USB_INTERFACES=:030000:010100:010200:
ID_USB_INTERFACE_NUM=01
ID_VENDOR=HiFimeDIY_Audio
ID_VENDOR_ENC=HiFimeDIY\x20Audio
ID_VENDOR_FROM_DATABASE=Genesys Logic, Inc.
ID_VENDOR_ID=262a
SEQNUM=2044
SOUND_INITIALIZED=1
SUBSYSTEM=sound
SYSTEMD_WANTS=sound.target
TAGS=:seat:systemd:
USEC_INITIALIZED=5712
UDEV [409.079517] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1 (usb)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1
DEVTYPE=usb_interface
ID_MODEL_FROM_DATABASE=USB-2.0 4-Port HUB
ID_VENDOR_FROM_DATABASE=Genesys Logic, Inc.
INTERFACE=1/1/0
MODALIAS=usb:v262Ap10E1d0001dc00dsc00dp00ic01isc01ip00in01
PRODUCT=262a/10e1/1
SEQNUM=2045
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=642712
UDEV [409.085432] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1 (usb)
ACTION=remove
BUSNUM=004
DEVNAME=/dev/bus/usb/004/010
DEVNUM=010
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1
DEVTYPE=usb_device
ID_BUS=usb
ID_MODEL=SA9023_USB_Audio
ID_MODEL_ENC=SA9023\x20USB\x20Audio
ID_MODEL_FROM_DATABASE=USB-2.0 4-Port HUB
ID_MODEL_ID=10e1
ID_REVISION=0001
ID_SERIAL=HiFimeDIY_Audio_SA9023_USB_Audio
ID_USB_INTERFACES=:030000:010100:010200:
ID_VENDOR=HiFimeDIY_Audio
ID_VENDOR_ENC=HiFimeDIY\x20Audio
ID_VENDOR_FROM_DATABASE=Genesys Logic, Inc.
ID_VENDOR_ID=262a
MAJOR=189
MINOR=393
PRODUCT=262a/10e1/1
SEQNUM=2047
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=619842
UDEV [411.697540] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1 (usb)
ACTION=add
BUSNUM=004
DEVNAME=/dev/bus/usb/004/011
DEVNUM=011
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1
DEVTYPE=usb_device
ID_BUS=usb
ID_MODEL=SA9023_USB_Audio
ID_MODEL_ENC=SA9023\x20USB\x20Audio
ID_MODEL_FROM_DATABASE=USB-2.0 4-Port HUB
ID_MODEL_ID=10e1
ID_REVISION=0001
ID_SERIAL=HiFimeDIY_Audio_SA9023_USB_Audio
ID_USB_INTERFACES=:030000:010100:010200:
ID_VENDOR=HiFimeDIY_Audio
ID_VENDOR_ENC=HiFimeDIY\x20Audio
ID_VENDOR_FROM_DATABASE=Genesys Logic, Inc.
ID_VENDOR_ID=262a
MAJOR=189
MINOR=394
PRODUCT=262a/10e1/1
SEQNUM=2048
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=33928
UDEV [411.699672] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.3 (usb)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.3
DEVTYPE=usb_interface
DRIVER=snd-usb-audio
ID_MODEL_FROM_DATABASE=USB-2.0 4-Port HUB
ID_VENDOR_FROM_DATABASE=Genesys Logic, Inc.
INTERFACE=1/2/0
MODALIAS=usb:v262Ap10E1d0001dc00dsc00dp00ic01isc02ip00in03
PRODUCT=262a/10e1/1
SEQNUM=2059
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=80939
UDEV [411.699773] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0 (usb)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0
DEVTYPE=usb_interface
ID_MODEL_FROM_DATABASE=USB-2.0 4-Port HUB
ID_VENDOR_FROM_DATABASE=Genesys Logic, Inc.
INTERFACE=3/0/0
MODALIAS=usb:v262Ap10E1d0001dc00dsc00dp00ic03isc00ip00in00
PRODUCT=262a/10e1/1
SEQNUM=2049
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=34043
UDEV [411.699840] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1 (usb)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1
DEVTYPE=usb_interface
ID_MODEL_FROM_DATABASE=USB-2.0 4-Port HUB
ID_VENDOR_FROM_DATABASE=Genesys Logic, Inc.
INTERFACE=1/1/0
MODALIAS=usb:v262Ap10E1d0001dc00dsc00dp00ic01isc01ip00in01
PRODUCT=262a/10e1/1
SEQNUM=2054
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=57387
UDEV [411.701367] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0006 (hi
d)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0006
HID_ID=0003:0000262A:000010E1
HID_NAME=HiFimeDIY Audio SA9023 USB Audio
HID_PHYS=usb-0000:00:1d.0-1.2.1/input0
MODALIAS=hid:b0003g0001v0000262Ap000010E1
SEQNUM=2050
SUBSYSTEM=hid
USEC_INITIALIZED=48481
UDEV [411.701544] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1 (sound)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1
ID_FOR_SEAT=sound-pci-0000_00_1d_0-usb-0_1_2_1_1_1
ID_PATH=pci-0000:00:1d.0-usb-0:1.2.1:1.1
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_2_1_1_1
SEQNUM=2055
SUBSYSTEM=sound
SYSTEMD_WANTS=sound.target
TAGS=:seat:systemd:
USEC_INITIALIZED=80503
UDEV [411.702560] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input25 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input25
EV=1
ID_BUS=usb
ID_FOR_SEAT=input-pci-0000_00_1d_0-usb-0_1_2_1_1_0
ID_INPUT=1
ID_MODEL=SA9023_USB_Audio
ID_MODEL_ENC=SA9023\x20USB\x20Audio
ID_MODEL_ID=10e1
ID_PATH=pci-0000:00:1d.0-usb-0:1.2.1:1.0
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_2_1_1_0
ID_REVISION=0001
ID_SERIAL=HiFimeDIY_Audio_SA9023_USB_Audio
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030000:010100:010200:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=HiFimeDIY_Audio
ID_VENDOR_ENC=HiFimeDIY\x20Audio
ID_VENDOR_ID=262a
MODALIAS=input:b0003v262Ap10E1e0100-e0,kramlsfw
NAME="HiFimeDIY Audio SA9023 USB Audio"
PHYS="usb-0000:00:1d.0-1.2.1/input0"
PRODUCT=3/262a/10e1/100
PROP=0
SEQNUM=2051
SUBSYSTEM=input
TAGS=:seat:
UNIQ=""
USEC_INITIALIZED=49147
UDEV [411.703227] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D0p (s
ound)
ACTION=add
DEVNAME=/dev/snd/pcmC1D0p
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D0p
MAJOR=116
MINOR=12
SEQNUM=2057
SUBSYSTEM=sound
TAGS=:uaccess:
USEC_INITIALIZED=80672
UDEV [411.704394] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0006/hid
raw/hidraw0 (hidraw)
ACTION=add
DEVNAME=/dev/hidraw0
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0006/hidraw/hidraw0
MAJOR=248
MINOR=0
SEQNUM=2053
SUBSYSTEM=hidraw
USEC_INITIALIZED=49353
UDEV [411.705903] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input25/event18 (
input)
ACTION=add
DEVLINKS=/dev/input/by-id/usb-HiFimeDIY_Audio_SA9023_USB_Audio-event-if00 /dev/input/by-path/pci-0000:00:1d.0-usb-0:1.2
.1:1.0-event
DEVNAME=/dev/input/event18
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input25/event18
ID_BUS=usb
ID_INPUT=1
ID_MODEL=SA9023_USB_Audio
ID_MODEL_ENC=SA9023\x20USB\x20Audio
ID_MODEL_ID=10e1
ID_PATH=pci-0000:00:1d.0-usb-0:1.2.1:1.0
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_2_1_1_0
ID_REVISION=0001
ID_SERIAL=HiFimeDIY_Audio_SA9023_USB_Audio
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030000:010100:010200:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=HiFimeDIY_Audio
ID_VENDOR_ENC=HiFimeDIY\x20Audio
ID_VENDOR_ID=262a
MAJOR=13
MINOR=82
SEQNUM=2052
SUBSYSTEM=input
USEC_INITIALIZED=49330
UDEV [411.714557] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/controlC1 (
sound)
ACTION=add
DEVLINKS=/dev/snd/by-id/usb-HiFimeDIY_Audio_SA9023_USB_Audio-01 /dev/snd/by-path/pci-0000:00:1d.0-usb-0:1.2.1:1.1
DEVNAME=/dev/snd/controlC1
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/controlC1
ID_BUS=usb
ID_MODEL=SA9023_USB_Audio
ID_MODEL_ENC=SA9023\x20USB\x20Audio
ID_MODEL_ID=10e1
ID_PATH=pci-0000:00:1d.0-usb-0:1.2.1:1.1
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_2_1_1_1
ID_REVISION=0001
ID_SERIAL=HiFimeDIY_Audio_SA9023_USB_Audio
ID_TYPE=audio
ID_USB_DRIVER=snd-usb-audio
ID_USB_INTERFACES=:030000:010100:010200:
ID_USB_INTERFACE_NUM=01
ID_VENDOR=HiFimeDIY_Audio
ID_VENDOR_ENC=HiFimeDIY\x20Audio
ID_VENDOR_ID=262a
MAJOR=116
MINOR=13
SEQNUM=2058
SUBSYSTEM=sound
TAGS=:uaccess:
USEC_INITIALIZED=80812
UDEV [411.759604] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D1p (s
ound)
ACTION=add
DEVNAME=/dev/snd/pcmC1D1p
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D1p
MAJOR=116
MINOR=11
SEQNUM=2056
SUBSYSTEM=sound
TAGS=:uaccess:
USEC_INITIALIZED=80575
UDEV [411.760476] change /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1 (sound)
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1
ID_BUS=usb
ID_FOR_SEAT=sound-pci-0000_00_1d_0-usb-0_1_2_1_1_1
ID_ID=usb-HiFimeDIY_Audio_SA9023_USB_Audio-01-Audio
ID_MODEL=SA9023_USB_Audio
ID_MODEL_ENC=SA9023\x20USB\x20Audio
ID_MODEL_FROM_DATABASE=USB-2.0 4-Port HUB
ID_MODEL_ID=10e1
ID_PATH=pci-0000:00:1d.0-usb-0:1.2.1:1.1
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_2_1_1_1
ID_REVISION=0001
ID_SERIAL=HiFimeDIY_Audio_SA9023_USB_Audio
ID_TYPE=audio
ID_USB_DRIVER=snd-usb-audio
ID_USB_INTERFACES=:030000:010100:010200:
ID_USB_INTERFACE_NUM=01
ID_VENDOR=HiFimeDIY_Audio
ID_VENDOR_ENC=HiFimeDIY\x20Audio
ID_VENDOR_FROM_DATABASE=Genesys Logic, Inc.
ID_VENDOR_ID=262a
SEQNUM=2060
SOUND_INITIALIZED=1
SUBSYSTEM=sound
SYSTEMD_WANTS=sound.target
TAGS=:seat:systemd:
USEC_INITIALIZED=80503the output of "sudo udevadm monitor" is:
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent
KERNEL[10520.780009] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input24/event17 (input)
UDEV [10520.783295] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input24/event17 (input)
KERNEL[10520.789826] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input24 (input)
KERNEL[10520.789859] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0005/hidraw/hidraw0 (hidraw)
KERNEL[10520.789871] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0005 (hid)
KERNEL[10520.789895] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0 (usb)
KERNEL[10520.789965] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D1p (sound)
KERNEL[10520.789999] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D0p (sound)
KERNEL[10520.790031] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/controlC1 (sound)
KERNEL[10520.790473] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1 (sound)
UDEV [10520.790483] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0005/hidraw/hidraw0 (hidraw)
KERNEL[10520.790494] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1 (usb)
UDEV [10520.790521] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input24 (input)
KERNEL[10520.790533] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.3 (usb)
UDEV [10520.790543] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D1p (sound)
KERNEL[10520.790615] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1 (usb)
UDEV [10520.790653] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D0p (sound)
UDEV [10520.790723] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/controlC1 (sound)
UDEV [10520.790843] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0005 (hid)
UDEV [10520.790870] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1 (sound)
UDEV [10520.791022] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.3 (usb)
UDEV [10520.791133] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1 (usb)
UDEV [10520.791157] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0 (usb)
UDEV [10520.795934] remove /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1 (usb)
KERNEL[10523.411837] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1 (usb)
KERNEL[10523.411961] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0 (usb)
KERNEL[10523.425856] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0006 (hid)
KERNEL[10523.426126] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input25 (input)
KERNEL[10523.426179] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input25/event17 (input)
KERNEL[10523.426268] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0006/hidraw/hidraw0 (hidraw)
KERNEL[10523.433989] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1 (usb)
KERNEL[10523.455486] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1 (sound)
KERNEL[10523.455508] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D1p (sound)
KERNEL[10523.455540] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D0p (sound)
KERNEL[10523.455580] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/controlC1 (sound)
KERNEL[10523.455608] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.3 (usb)
UDEV [10523.463039] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1 (usb)
UDEV [10523.464322] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0 (usb)
UDEV [10523.464384] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1 (usb)
UDEV [10523.464409] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.3 (usb)
UDEV [10523.465345] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0006 (hid)
UDEV [10523.465380] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1 (sound)
UDEV [10523.466303] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input25 (input)
UDEV [10523.466417] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/0003:262A:10E1.0006/hidraw/hidraw0 (hidraw)
UDEV [10523.467311] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.0/input/input25/event17 (input)
UDEV [10523.468387] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D1p (sound)
UDEV [10523.468659] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D0p (sound)
KERNEL[10523.468942] change /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1 (sound)
UDEV [10523.474581] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/controlC1 (sound)
UDEV [10523.475757] change /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1 (sound)please not that my usb soundcard is attached through a usb hub to my laptop and that it was attached when I ran the command, then removed it and attached it again.
tried to use those udev rules:
KERNEL=="pcmC1D1p", DRIVERS=="usb", ACTION=="add", RUN+="/bin/bash -c '/home/me/dotfiles/soundconf.sh attached'"
KERNEL=="pcmC1D1p", DRIVERS=="usb", ACTION=="remove", RUN+="/bin/bash -c '/home/me/dotfiles/soundconf.sh detached'"to no avail unfortunately...
thanks a lot for your patience and time
!
Offline
I have not much time to spend at this moment, but at first glance what I see useful for your rule writing is these parts:
UDEV [411.703227] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D0p (s
ound)
ACTION=add
DEVNAME=/dev/snd/pcmC1D0p
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D0p
MAJOR=116
MINOR=12
SEQNUM=2057
SUBSYSTEM=sound
TAGS=:uaccess:
USEC_INITIALIZED=80672and
DEV [411.759604] add /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D1p (s
ound)
ACTION=add
DEVNAME=/dev/snd/pcmC1D1p
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2/4-1.2.1/4-1.2.1:1.1/sound/card1/pcmC1D1p
MAJOR=116
MINOR=11
SEQNUM=2056
SUBSYSTEM=sound
TAGS=:uaccess:
USEC_INITIALIZED=80575The 'KERNEL==' match corresponds to the DEVNAME value, which is not exactly "pcmC1D[01]p" but "snd/pcmC1D[01]p"
And instead of 'DRIVERS=="usb"' you could use 'SUBSYSTEM=="sound"'
Is it possible to see the content of the soundconf.sh script?
Sorry I have no more time now to go further.. Please continue to post your progresses writing the udev rule.
Best wishes.
Offline
thanks alot for your time berbae ![]()
the script is here https://github.com/likyng/dotfiles/blob … undconf.sh
#!/bin/bash
# shell script to set default sound device to usb DAC, if attached
# gets called through udev rule upon usb attachment/detachment
usbdac=$(asoundconf list | sed -n '3{p;q}')
intelhda=$(asoundconf list | sed -n '2{p;q}')
if [[ "attached" == "$1" ]]; then
asoundconf set-default-card $usbdac
#echo "$usbdac ($usbdac) set as default audio card :)!"
exit 1
fi
if [[ "detached" == "$1" ]]; then
asoundconf set-default-card $intelhda
#echo "intelhda ($intelhda) set as default audio card :)!"
exit 1
fii'll try your suggestion though!! thanks ![]()
Offline
thaks a lot, i got it solved!
the udev rule actually worked fine (last one) but my script was wrong. I was executing asoundconfig as root user, which obviously doesnt have any effect on my user's soundconfig..
switched to runuser -l me -c '...' and works
!
thanks!!
Offline