13

I've got a Thinkpad and would like to use the ThinkLight (the white flash light above the screen designed to light up the keyboard) for notifications on incoming Jabber messages.

It is easy to realise as one only needs to change /sys/class/leds/tpacpi::thinklight/brightness to 255. I'll do it with a simple Bash script, which will let the light blink for three times.

But to be able to do this, I need to change the permissions, that not only root is able to change this file.
And I do not want to sudo chmod o+w /sys/class/leds/tpacpi::thinklight/brightness after each and every boot.

I think, the best solution is using udev for this. However, I've never used udev before and I'm quite confused by the tutorials I found online.

I tried this udev rule:

KERNEL=="tpacpi::thinklight", MODE="0666"

as well as

KERNEL="thinklight", MODE="0666"

But it does not work. Though I'm not getting errors while running udevadm test /class/leds

Thanks for any help and hits. Or maybe other solutions.

mattdm
  • 40,245
Torbjörn
  • 308

2 Answers2

8

I'm using two udev rules (in a file under /etc/udev/rules.d/) as follows, to give members of group leds access to all LEDs:

SUBSYSTEM=="leds", ACTION=="add", RUN+="/bin/chgrp -R leds /sys%p", RUN+="/bin/chmod -R g=u /sys%p"
SUBSYSTEM=="leds", ACTION=="change", ENV{TRIGGER}!="none", RUN+="/bin/chgrp -R leds /sys%p", RUN+="/bin/chmod -R g=u /sys%p"

Note the ACTION=="change" rule is needed to handle dynamically created attributes. For example, if the LED's trigger is set to "timer" (echo timer > trigger), then extra attributes delay_on and delay_off are created. The change action is specified so that these new attributes have their group and permissions set.

I've noticed that a change event is generated every time the LED is turned off by writing 0 to /sys/class/leds/.../brightness. This seems to be due to the Linux LED driver code clearing triggers whenever brightness is set to 0. That is why the second rule has the ENV{TRIGGER}!="none" condition, to prevent the rule triggering every time an LED is turned off.

My testing shows that change event when brightness is set to 0 no longer happens in kernel 5.4. Looking in the Linux git repository, it looks as though this was fixed in kernel 4.9. So for kernels newer than 4.9, the ENV{TRIGGER}!="none" part of the second rule isn't needed.

1

I think you have the wrong 'KERNEL' setting. From this awesome doc for writing and debugging udev rules:

http://www.reactivated.net/writing_udev_rules.html#basic

I think you need KERNEL=brightness, and perhaps a SUBSYSTEM=leds

Then, in case your distro lacks inotify support. Make sure your changes are being seen by udevd:

# udevcontrol reload_rules
polynomial
  • 2,461
  • 20
  • 15