You are not logged in.

#1 2022-07-14 22:22:10

ReD55
Member
Registered: 2022-07-14
Posts: 7

How to write a udev rule that syncs LEDs?

I was trying to write a rule that syncs my numpad led to my mute led, because my laptop does not have a numpad led, and it's flipping me out. Here is what I tried so far :

udevadm info -ap /sys/class/leds/input3::numlock
result : 
 looking at device '/devices/platform/i8042/serio0/input/input3/input3::numlock':
    KERNEL=="input3::numlock"
    SUBSYSTEM=="leds"
    DRIVER==""
    ATTR{brightness}=="1"
    ATTR{max_brightness}=="1"
    ATTR{power/control}=="auto"
    ATTR{power/runtime_active_time}=="0"
    ATTR{power/runtime_status}=="unsupported"
    ATTR{power/runtime_suspended_time}=="0" 

From that output I thought that the relevant information are KERNEL and SUBSYSTEM. So I created a udev rule in (/etc/udev/rules.d/50-numpad.rules) :

ACTION=="change",SUBSYSTEM=="leds",KERNEL=="input3::numlock"
RUN+= "/etc/udev/rules.d/scripts/sync-numpad-led-to-mute-led.sh"

sync-numpad-led-to-mute-led.sh (-rwxr-xr-x 1 root root ) content :

cat /sys/class/leds/input3::numlock/brightness > /tmp/test
cat /sys/class/leds/input3::numlock/brightness > /sys/class/leds/hda::mute/brightness

Running this script as a normal user will result in a properly written test file but won't change the LED, due to insufficient permissions. (claims that my script would be executed by user systemd-udev having root privileges, when triggered by udev)

My problem is that not even the /tmp/test file changes, indicating that the rule is not fired. But things look very odd every time I press numpad (I did run udevadm control --reload) :

udevadm control --log-priority=debug
journalctl -f

ouput everytime I press numpad : 
atkbd serio0: Spurious NAK on isa0060/serio0. Some program might be trying to access hardware directly.

My system also has no systemd-udev user (userdbctl).

System details :

OS: Arch Linux x86_64
Kernel: 5.18.10-arch1-1
Host: HP Laptop 17-cp0xxx

Thanks to anyone who can help smile

Last edited by ReD55 (2022-07-15 13:37:41)

Offline

Board footer

Powered by FluxBB