[openwrt/openwrt] base-files: configure LED when added

LEDE Commits lede-commits at lists.infradead.org
Thu Oct 3 15:08:19 PDT 2024


dangole pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/511e8f84d093b6fbb93b044c2ab150e613b88171

commit 511e8f84d093b6fbb93b044c2ab150e613b88171
Author: Daniel Golle <daniel at makrotopia.org>
AuthorDate: Thu Oct 3 16:25:36 2024 +0100

    base-files: configure LED when added
    
    Currently LED configuration is only carried out once during boot.
    Apply LED configuration also with a hotplug call when a new LED gets
    added later.
    
    Signed-off-by: Daniel Golle <daniel at makrotopia.org>
---
 package/base-files/files/etc/hotplug.d/leds/00-init | 3 +++
 package/base-files/files/etc/init.d/led             | 7 +++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/package/base-files/files/etc/hotplug.d/leds/00-init b/package/base-files/files/etc/hotplug.d/leds/00-init
new file mode 100644
index 0000000000..0303e2bc47
--- /dev/null
+++ b/package/base-files/files/etc/hotplug.d/leds/00-init
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+[ "$ACTION" = "add" ] && /etc/init.d/led start "$DEVICENAME"
diff --git a/package/base-files/files/etc/init.d/led b/package/base-files/files/etc/init.d/led
index ea2688cab2..5130ac7d41 100755
--- a/package/base-files/files/etc/init.d/led
+++ b/package/base-files/files/etc/init.d/led
@@ -64,6 +64,8 @@ load_led() {
 	config_get gpio $1 gpio "0"
 	config_get_bool inverted $1 inverted "0"
 
+	[ "$2" ] && [ "$sysfs" != "$2" ] && return
+
 	# execute application led trigger
 	[ -f "/usr/libexec/led-trigger/${trigger}" ] && {
 		. "/usr/libexec/led-trigger/${trigger}"
@@ -121,7 +123,7 @@ load_led() {
 					[ -e "/sys/class/leds/${sysfs}/$m" ] && \
 						echo 1 > /sys/class/leds/${sysfs}/$m
 				done
-				echo $interval > /sys/class/leds/${sysfs}/interval
+				echo $interval > /sys/class/leds/${sysfs}/interval 2>/dev/null
 			}
 			;;
 
@@ -171,6 +173,7 @@ start() {
 		[ -s /var/run/led.state ] && {
 			local led trigger brightness color
 			while read led trigger brightness color; do
+				[ "$1" ] && [ "$1" != "$led" ] && continue
 				[ -e "/sys/class/leds/$led/trigger" ] && \
 					echo "$trigger" > "/sys/class/leds/$led/trigger"
 
@@ -185,6 +188,6 @@ start() {
 		}
 
 		config_load system
-		config_foreach load_led led
+		config_foreach load_led led "$1"
 	}
 }




More information about the lede-commits mailing list