Skip to content

Commit 2960ffa

Browse files
avoid binary led parameters, better handle :link triggers (#7337)
1 parent 8b9fd15 commit 2960ffa

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

packages/bsp/common/lib/systemd/system/armbian-led-state.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[Unit]
66
Description=Armbian leds state
7-
After=timers.target
7+
After=sysinit.target
88
Conflicts=shutdown.target
99
DefaultDependencies=no
1010

packages/bsp/common/usr/lib/armbian/armbian-led-state-save.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,25 @@ function store_led() {
3535

3636
# In case the trigger is any of the kbd-*, don't store any other parameter
3737
# This avoids num/scroll/capslock from being restored at startup
38-
# In case trigger is representing link-state for any network, don't store its previous state
39-
# This avoids ghost wan/lan/etc (led up while cable unplugged)
40-
[[ "$TRIGGER_VALUE" =~ kbd-* || "$TRIGGER_VALUE" == *":link" ]] && return
38+
[[ "$TRIGGER_VALUE" =~ kbd-* ]] && return
4139

4240
COMMAND_PARAMS="$CMD_FIND $PATH/ -maxdepth 1 -type f ! -iname uevent ! -iname trigger -perm /u+w -printf %f\\n"
4341
PARAMS=$($COMMAND_PARAMS)
4442

43+
# In case trigger is representing link-state for any network, use
44+
# bash substitution to remove the brightness parameter and avoid
45+
# ghost wan/lan/etc (led up while cable unplugged)
46+
[[ "$TRIGGER_VALUE" == *":link" ]] && PARAMS=${PARAMS//"brightness"/}
47+
4548
for PARAM in $PARAMS; do
4649

4750
PARAM_PATH="$PATH/$PARAM"
4851
VALUE=$(<$PARAM_PATH)
4952

53+
# If the variable contains non-printable characters
54+
# suppose it contains binary and skip it
55+
[[ "$VALUE" =~ [[:cntrl:]] ]] && continue
56+
5057
echo "$PARAM=$VALUE" >> $DESTINATION
5158

5259
done
@@ -60,9 +67,7 @@ for LED in /sys/class/leds/*; do
6067
[[ -d "$LED" ]] || continue
6168

6269
# Skip saving state for directories starting with enP e.g. enP1p1s0-0::lan enP2p1s0-2::lan etc. etc.
63-
if [[ "$(/usr/bin/basename "$LED")" == enP* ]]; then
64-
continue
65-
fi
70+
[[ "$(/usr/bin/basename "$LED")" == enP* ]] && continue
6671

6772
store_led $LED $STATE_PATH
6873
echo >> $STATE_PATH

0 commit comments

Comments
 (0)