我想通过/sys/class/backlight/radeon_bl0/brightness
文件更改显示器的亮度。但该文件具有-rw-r--r--.
权限,因此只有 root 可以写入它。本文说我可以配置 udev 规则来更改权限。这不起作用。我稍微修改了规则以匹配我的计算机。我的显卡是radeon_b10
,不是acpi_video0
。
ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="radeon_b10", RUN+="/usr/bin/chgrp video /sys/class/backlight/%k/brightness"
ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="radeon_b10", RUN+="/usr/bin/chmod g+w /sys/class/backlight/%k/brightness"
我已经尝试了一切。使用 监控规则$ udevadm monitor
并使用 触发规则# udevadm trigger --action=add /sys/class/backlight/radeon_bl0
。规则已被触发,但文件/sys/class/backlight/%k/brightness
仍然是:
-rw-r--r--. 1 root root 4096 Aug 1 16:09 brightness
(输出自$ ll -a /sys/class/backlight/radeon_bl0/
)
为什么udev不执行该RUN
语句?
有关我的系统的信息:
[marian@bagr ~]$ uname -a
Linux bagr 4.17.9-200.fc28.x86_64 #1 SMP Mon Jul 23 21:41:29 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[marian@bagr ~]$ ll -a /sys/class/backlight/radeon_bl0/
total 0
drwxr-xr-x. 3 root root 0 Aug 1 2018 .
drwxr-xr-x. 6 root root 0 Aug 1 2018 ..
-r--r--r--. 1 root root 4096 Aug 1 16:09 actual_brightness
-rw-r--r--. 1 root root 4096 Aug 1 16:09 bl_power
-rw-r--r--. 1 root root 4096 Aug 1 16:09 brightness
lrwxrwxrwx. 1 root root 0 Aug 1 16:09 device -> ../../card0-eDP-1
-r--r--r--. 1 root root 4096 Aug 1 16:09 max_brightness
drwxr-xr-x. 2 root root 0 Aug 1 16:09 power
lrwxrwxrwx. 1 root root 0 Aug 1 2018 subsystem -> ../../../../../../../class/backlight
-r--r--r--. 1 root root 4096 Aug 1 16:09 type
-rw-r--r--. 1 root root 4096 Aug 1 16:09 uevent
[marian@bagr ~]$ udevadm info -q all -a /sys/class/backlight/radeon_bl0
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/pci0000:00/0000:00:01.0/drm/card0/card0-eDP-1/radeon_bl0':
KERNEL=="radeon_bl0"
SUBSYSTEM=="backlight"
DRIVER==""
ATTR{actual_brightness}=="30"
ATTR{bl_power}=="0"
ATTR{brightness}=="30"
ATTR{max_brightness}=="255"
ATTR{type}=="raw"
looking at parent device '/devices/pci0000:00/0000:00:01.0/drm/card0/card0-eDP-1':
KERNELS=="card0-eDP-1"
SUBSYSTEMS=="drm"
DRIVERS==""
ATTRS{dpms}=="On"
ATTRS{edid}==""
ATTRS{enabled}=="enabled"
ATTRS{status}=="connected"
looking at parent device '/devices/pci0000:00/0000:00:01.0/drm/card0':
KERNELS=="card0"
SUBSYSTEMS=="drm"
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:01.0':
KERNELS=="0000:00:01.0"
SUBSYSTEMS=="pci"
DRIVERS=="radeon"
ATTRS{ari_enabled}=="0"
ATTRS{boot_vga}=="1"
ATTRS{broken_parity_status}=="0"
ATTRS{class}=="0x030000"
ATTRS{consistent_dma_mask_bits}=="40"
ATTRS{current_link_speed}=="Unknown speed"
ATTRS{current_link_width}=="0"
ATTRS{d3cold_allowed}=="1"
ATTRS{device}=="0x9850"
ATTRS{dma_mask_bits}=="40"
ATTRS{driver_override}=="(null)"
ATTRS{enable}=="1"
ATTRS{irq}=="35"
ATTRS{local_cpulist}=="0-3"
ATTRS{local_cpus}=="f"
ATTRS{max_link_speed}=="Unknown speed"
ATTRS{max_link_width}=="255"
ATTRS{msi_bus}=="1"
ATTRS{numa_node}=="-1"
ATTRS{power_dpm_force_performance_level}=="auto"
ATTRS{power_dpm_state}=="balanced"
ATTRS{power_method}=="dpm"
ATTRS{power_profile}=="default"
ATTRS{revision}=="0x40"
ATTRS{subsystem_device}=="0x81f5"
ATTRS{subsystem_vendor}=="0x103c"
ATTRS{vendor}=="0x1002"
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
答案1
一种可能的原因是要更改的文件尚不存在。
运行脚本而不是 chown 和 chmod,该脚本可以检查目标是否存在并将信息写入日志文件。
答案2
我使用了change
操作而不是add
一切正常:
ACTION=="change", SUBSYSTEM=="backlight", KERNEL=="radeon_b10", RUN+="/usr/bin/chgrp video /sys/class/backlight/%k/brightness"
ACTION=="change", SUBSYSTEM=="backlight", KERNEL=="radeon_b10", RUN+="/usr/bin/chmod g+w /sys/class/backlight/%k/brightness"