You are not logged in.
I would like to control the backlight as non privileged user. So I need write access to the brightness property of the device (nvidia_backlight).
Because I want the rule executed whenever I modprobe the backlight driver a tmpfile rule does not seem the right way to do this, since this is only executed at boot time. So I made this udev rule. However the "RUN" part does not seem to be executed.
properties of the device:
# udevadm info -a -p /sys/class/backlight/nvidia_backlight
Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.
looking at device '/devices/virtual/backlight/nvidia_backlight':
KERNEL=="nvidia_backlight"
SUBSYSTEM=="backlight"
DRIVER==""
ATTR{type}=="raw"
ATTR{brightness}=="44000"
ATTR{bl_power}=="0"
ATTR{max_brightness}=="44000"
ATTR{actual_brightness}=="44000"contents of /etc/udev/rules.d/97-nvidia_backlight.rules:
KERNEL=="nvidia_backlight", SUBSYSTEM=="backlight", RUN+="/usr/bin/chmod 666 /sys/class/backlight/%k/brightness"testing the rules it does seem as if the RUN command would be executed:
#udevadm test /sys/class/backlight/nvidia_backlight
calling: test
version 204
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: 204
file size: 5632867 bytes
header size 80 bytes
strings 1260755 bytes
nodes 4372032 bytes
load module index
(...)
read rules file: /etc/udev/rules.d/96-usb-disable-autosuspend.rules
read rules file: /etc/udev/rules.d/97-nvidia_backlight.rules
read rules file: /usr/lib/udev/rules.d/99-laptop-mode.rules
read rules file: /usr/lib/udev/rules.d/99-systemd.rules
rules contain 49152 bytes tokens (4096 * 12 bytes), 22261 bytes strings
3744 strings (47376 bytes), 2539 de-duplicated (26321 bytes), 1206 trie nodes used
RUN '/usr/bin/chmod 666 /sys/class/backlight/%k/brightness' /etc/udev/rules.d/97-nvidia_backlight.rules:3
ACTION=add
DEVPATH=/devices/virtual/backlight/nvidia_backlight
SUBSYSTEM=backlight
USEC_INITIALIZED=5669137425
run: '/usr/bin/chmod 666 /sys/class/backlight/nvidia_backlight/brightness'
unload module indexHowever after reloading the driver, the 'brightness' property does not have get the 666 permission that I expected:
# rmmod nvidia-bl && modprobe nvidia-bl
# ll /sys/class/backlight/nvidia_backlight/
total 0
drwxr-xr-x 3 root root 0 Jul 25 20:02 .
drwxr-xr-x 4 root root 0 Jul 25 18:48 ..
drwxr-xr-x 2 root root 0 Jul 25 20:02 power
-r--r--r-- 1 root root 4.0K Jul 25 20:02 actual_brightness
-rw-r--r-- 1 root root 4.0K Jul 25 20:02 bl_power
-rw-r--r-- 1 root root 4.0K Jul 25 20:02 brightness
-r--r--r-- 1 root root 4.0K Jul 25 20:02 max_brightness
lrwxrwxrwx 1 root root 0 Jul 25 20:02 subsystem -> ../../../../class/backlight
-r--r--r-- 1 root root 4.0K Jul 25 20:02 type
-rw-r--r-- 1 root root 4.0K Jul 25 20:02 ueventI executed 'udevadm trigger', but still the same result. Does anyone know what causes this?
Last edited by rwd (2013-07-27 06:19:01)
Offline
Maybe a race to create /sys/class/backlight/%k/brightness
Change the RUN+= to execute a *script*, e.g. /root/bin/nvidia-debug or whatever, then you can easily add debugging info to that script, to e.g. write a little logfile in /tmp/
Offline
Just to be sure if the RUN part gets executed at all I changed it to:
RUN+="touch /tmp/udevtest "I then did
# udevadm test /sys/class/backlight/nvidia_backlight
(...)
rules contain 49152 bytes tokens (4096 * 12 bytes), 22188 bytes strings
3743 strings (47294 bytes), 2538 de-duplicated (26312 bytes), 1206 trie nodes used
RUN 'touch /tmp/udevtest ' /etc/udev/rules.d/97-nvidia_backlight.rules:4
ACTION=add
DEVPATH=/devices/virtual/backlight/nvidia_backlight
SUBSYSTEM=backlight
USEC_INITIALIZED=16131026483
run: 'touch /tmp/udevtest '
unload module indexHowever if I do 'udevadm trigger', or a 'rmmod nvidia_bl && modprobe nvidia_bl' no '/tmp/udevtest' is created. I'm kinda stumped.
Last edited by rwd (2013-07-27 05:42:44)
Offline
I don't have nvidia, but rather Intel HD4000. But I have a udev rule that sets the brightness of my screen on boot. So the rule is strikingly similar to what you have there. Here is what I have:
$ cat /etc/udev/rules.d/44-backlight.rules
ACTION=="add", KERNEL=="acpi_video0", SUBSYSTEM=="backlight", SUBSYSTEMS=="pci", DRIVERS=="i915", ATTR{brightness}="4"I'm not sure why I decided to include the SUBSYSTEMS or DRIVERS... this was the first udev rule I ever wrote. So I guess I just wanted to make sure I had enough parameters. But it works. I am also not sure why I chose 44... but that also seems to work.
One thing I did notice when I was learning is that if I had ACTION="add|change" then it would not let me change the brightness. It would always set it back to '4'.
I'm not sure if any of this will help you, but you don't seem to be getting much traction with this thread... so at the very least I'll bump it to the top of the "new" list for you.
Offline
Thanks Woofy, but I have found the cause: it seems changes to .rules files are only picked up when I rename the .rules file. Also full path to the executable is necessary, I assume because it is not executed in a shell.
Last edited by rwd (2013-07-27 06:41:24)
Offline
Thanks Woofy, but I have found the cause: it seems changes to .rules files are only picked up when I rename the .rules file. Also full path to the executable is necessary, I assume because it is not executed in a shell.
The full path thing is not terribly surprising... I didn't think of it, but not a shock. OTOH, I would have never in a million zillion years have guessed that the changes would only be picked up on a rules name change! How did you figure this out?
Offline
I would have never in a million zillion years have guessed that the changes would only be picked up on a rules name change! How did you figure this out?
I first wanted to see if there was some rule in /usr/lib/udev/rules.d/ that interfered with mine, so renamed mine with a high number as a prefix. Since that seemed to work I kept giving it lower prefixes to see if a specific rule in /usr/lib/udev/rules.d/ would cause the trouble, but my rule kept working no matter which prefix I gave it, so my conclusion was that just the renaming made it work.
Offline
Very interesting! Thanks for sharing rwd. I will lodge that bit of information into my brain somewhere for possible later use.
Offline
I wonder if this isn't some bug. I would have assumed ionotify would be used to check for file changes.
Offline
only picked up when
No, I expect you're wrong. Try instead:
udevadm control --reloadOffline
rwd wrote:only picked up when
No, I expect you're wrong. Try instead:
udevadm control --reload
Well that would surely reload all rules files, but shouldn't changing the contents of a .rules file be enough? I know for sure that in my case it wasn't.
Last edited by rwd (2013-07-27 08:09:52)
Offline