Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
udev USB keyboard add/remove multiple events
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
lyallp
Veteran
Veteran


Joined: 15 Jul 2004
Posts: 1403
Location: Adelaide/Australia

PostPosted: Sun Apr 23, 2017 11:54 am    Post subject: udev USB keyboard add/remove multiple events Reply with quote

Hi,
I am trying to do the eudyptula challenge and one of the tasks is to load a kernel module when a USB keyboard is inserted.

The only problem I have is that my udev rules file triggers 4 times when I plug in a USB Razer Blackwidow into my Gentoo VM via the Virtualbox USB control.

Whilst, technically, I am able to meet the challenge requirements by simply going through the module load 4 times (3 times superfluously), I would prefer to load/unload only once.

I figure I need to examine an ENV value for a specific value but am unsure as to which one is appropriate. I suspect the additional firings are for things like LEDs.

I am only looking for assistance on what to look at, not how, but I guess this forum topic would be a good place to put some educational material on this matter.

My current rule file, whilst overly verbose and quite capable of being only one line, is as follows:-

Code:
# only need the one line that sets up RUN+= but in case I have to
# process extra actions or wish to do additional interesting stuff

# only interested in Keyboard events
ENV{.INPUT_CLASS}!="kbd", GOTO="task05_end"

# Only interested in Add events
ACTION=="add", GOTO="task05_add"

# Ignore everything else
GOTO="task05_end"


LABEL="task05_add"

# setup add/remove commands (look in system log)
RUN+="/usr/bin/logger ADD KBD"
ENV{REMOVE_CMD}="/usr/bin/logger REMOVE KBD"

GOTO="task05_end"


LABEL="task05_end"

Currently, syslog/dmsg generates the following, showing the 4 triggers.
Code:

Apr 23 21:06:51 gentoo-vm kernel: usb 1-1: new full-speed USB device number 9 using ohci-pci
Apr 23 21:06:51 gentoo-vm kernel: usb 1-1: New USB device found, idVendor=1532, idProduct=010e
Apr 23 21:06:51 gentoo-vm kernel: usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Apr 23 21:06:51 gentoo-vm kernel: usb 1-1: Product: Razer BlackWidow
Apr 23 21:06:51 gentoo-vm kernel: usb 1-1: Manufacturer: Razer
Apr 23 21:06:51 gentoo-vm kernel: input: Razer Razer BlackWidow as /devices/pci0000:00/0000:00:06.0/usb1/1-1/1-1:1.0/0003:1532:010E.0016/input/input28
Apr 23 21:06:51 gentoo-vm kernel: hid-generic 0003:1532:010E.0016: input,hidraw0: USB HID v1.11 Keyboard [Razer Razer BlackWidow] on usb-0000:00:06.0-1/input0
Apr 23 21:06:51 gentoo-vm kernel: input: Razer Razer BlackWidow as /devices/pci0000:00/0000:00:06.0/usb1/1-1/1-1:1.1/0003:1532:010E.0017/input/input29
Apr 23 21:06:51 gentoo-vm kernel: hid-generic 0003:1532:010E.0017: input,hidraw1: USB HID v1.11 Keyboard [Razer Razer BlackWidow] on usb-0000:00:06.0-1/input1
Apr 23 21:06:51 gentoo-vm root[24770]: ADD KBD
Apr 23 21:06:51 gentoo-vm kernel: input: Razer Razer BlackWidow as /devices/pci0000:00/0000:00:06.0/usb1/1-1/1-1:1.2/0003:1532:010E.0018/input/input30
Apr 23 21:06:51 gentoo-vm kernel: hid-generic 0003:1532:010E.0018: input,hidraw2: USB HID v1.11 Mouse [Razer Razer BlackWidow] on usb-0000:00:06.0-1/input2
Apr 23 21:06:51 gentoo-vm root[24773]: ADD KBD
Apr 23 21:06:51 gentoo-vm root[24775]: ADD KBD
Apr 23 21:06:51 gentoo-vm root[24776]: ADD KBD
Apr 23 21:07:08 gentoo-vm kernel: usb 1-1: USB disconnect, device number 9
Apr 23 21:07:08 gentoo-vm root[24782]: REMOVE KBD
Apr 23 21:07:08 gentoo-vm root[24785]: REMOVE KBD
Apr 23 21:07:08 gentoo-vm root[24787]: REMOVE KBD
Apr 23 21:07:08 gentoo-vm root[24790]: REMOVE KBD

_________________
...Lyall
Back to top
View user's profile Send private message
lyallp
Veteran
Veteran


Joined: 15 Jul 2004
Posts: 1403
Location: Adelaide/Australia

PostPosted: Sun Apr 23, 2017 1:19 pm    Post subject: Reply with quote

I have a solution, but am unsure if it is 'correct'.

Basically, I look for ID_USB_INTERFACE_NUM of 00 and when the DEVNAME is blank.
If these 2 conditions are met, then I will load my module.

Suggestions welcomed.

Revised Rule file
Code:

# only need the one line that sets up RUN+= but in case I have to
# process extra actions

# only interested in Keyboard events
ENV{.INPUT_CLASS}!="kbd", GOTO="task05_end"

# Only interested in Add events
ACTION=="add", GOTO="task05_add"
GOTO="task05_end"

LABEL="task05_add"

# Only interested in the first device,
ENV{ID_USB_INTERFACE_NUM}!="00", GOTO="task05_end"

# Only interested if there is an empty device name, get 2 events, one with, one without.
ENV{DEVNAME}=="", GOTO="task05_end"

# setup add/remove commands (look in system log)
RUN+="/usr/bin/logger ADD KBD $env{DEVNAME}"
ENV{REMOVE_CMD}="/usr/bin/logger REMOVE KBD $env{DEVNAME}"

GOTO="task05_end"


LABEL="task05_end"

_________________
...Lyall
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum