diff mbox

[OpenWrt-Devel] base-files: led input trigger error message if kernel module is not loaded

Message ID 20141229165450.39eafa9f@erker.lan
State Accepted
Headers show

Commit Message

Lars Kruse Dec. 29, 2014, 3:54 p.m. UTC
Hi,

I use a custom made image (for our local wifi community) with a TL-WDR4300.
Recently I disabled the config line CONFIG_PACKAGE_kmod-ledtrig-usbdev.
The absence of this module causes a bootup error message:

  root@AP-1-203:/etc/rc.d# /etc/init.d/led start setting up led USB1
  sh: write error: Invalid argument
  /etc/rc.common: eval: line 1: can't create /sys/class/leds/tp-link:green:usb1/device_name: nonexistent directory
  /etc/rc.common: eval: line 1: can't create /sys/class/leds/tp-link:green:usb1/activity_interval: nonexistent directory
  setting up led USB2
  sh: write error: Invalid argument
  /etc/rc.common: eval: line 1: can't create /sys/class/leds/tp-link:green:usb2/device_name: nonexistent directory
  /etc/rc.common: eval: line 1: can't create /sys/class/leds/tp-link:green:usb2/activity_interval: nonexistent directory
  setting up led WLAN2G

After installing and loading the "ledtrig-usbdev" module the above runs fine
without error messages.

Attached you find a patch that checks the result of the trigger attempt and
emits a graceful error message with an explanation regarding the missing kernel
module instead of the rather mysterious error messages above.

Cheers,
Lars


Verify the support of the led trigger input source and complain in a helpful
way if modules are missing during bootup.

Signed-off-by: Lars Kruse <devel@sumpfralle.de>
---
--
diff mbox

Patch

diff -ruN a/openwrt/package/base-files/files/etc/init.d/led b/openwrt/package/base-files/files/etc/init.d/led
--- a/openwrt/package/base-files/files/etc/init.d/led
+++ b/openwrt/package/base-files/files/etc/init.d/led
@@ -40,7 +40,11 @@ 
                        [ $default -eq 1 ] ||
                                echo 0 >/sys/class/leds/${sysfs}/brightness
                }
-               echo $trigger > /sys/class/leds/${sysfs}/trigger
+               # this may fail if the module is not loaded
+               if ! echo $trigger > /sys/class/leds/${sysfs}/trigger 2>/dev/null; then
+                       echo >&2 "Skipping trigger '$trigger' for led '$name' due to missing kernel module"
+                       return 0
+               fi
                case "$trigger" in
                "netdev")
                        [ -n "$dev" ] && {