diff --git a/rootfs/overlay/opt/mu300/bin/mu300-led b/rootfs/overlay/opt/mu300/bin/mu300-led index a9ca2054..763bdcfa 100755 --- a/rootfs/overlay/opt/mu300/bin/mu300-led +++ b/rootfs/overlay/opt/mu300/bin/mu300-led @@ -116,7 +116,15 @@ case "$1 ${2:-}" in for l in $SIREN; do write "$l" 0; done if awake; then show_all; fi ;; # the U30 Air's white is its power LED, the F50's blue its data LED "siren "*) # (alarm on runs this in the background) + # Only the siren named in the pid file runs: one left behind (its alarm switched off while it was + # between writes, a restarted service) stops by itself instead of flashing along with the new one. + # The file is written just after the start, so a missing one counts only after the first round. + n=0 while :; do + own=$(cat "$SIREN_PID" 2>/dev/null) + if [ -n "$own" ]; then [ "$own" = $$ ] || exit 0 + elif [ $n -gt 0 ]; then exit 0; fi + n=$((n + 1)) for on in $SIREN; do for l in $SIREN; do [ "$l" = "$on" ] || write "$l" 0; done write "$on" 1; nap 0.25 diff --git a/tests/test_device_scripts.py b/tests/test_device_scripts.py index 44bc6262..495f4c12 100644 --- a/tests/test_device_scripts.py +++ b/tests/test_device_scripts.py @@ -1,5 +1,6 @@ """Small device scripts, against a fake / (MU300_SYSROOT) and stub commands: mu300-device, mu300-lan-ip, mu300-led, mu300-ttl. They run on Ubuntu (dash, bash) and OpenWrt (busybox ash).""" +import os import shutil import time import unittest @@ -177,6 +178,27 @@ class Led(ShellTest): self.led(shell, 'f50', 'data', '5g') # one LED: blue on 5G too self.assertEqual(self.state()['sc27xx:blue'], '255') + def test_stale_siren_stops(self): + # a siren the pid file does not name (left behind by a restart) stops by itself: two of them flashed + # together, white lit throughout + for shell in self.each_shell(): + self.reset() + pid = self.root / 'run/mu300/led-siren.pid' + self.led(shell, 'u30air', 'alarm', 'on') + p = int(pid.read_text()) + pid.write_text('1\n') # someone else's now + deadline = time.time() + 3 + while time.time() < deadline: + try: + os.kill(p, 0) + except ProcessLookupError: + break + time.sleep(0.1) + else: + os.kill(p, 15) + self.fail('the stale siren kept running') + pid.unlink() + def test_vendor_ldo_switches_on_5_4(self): # the 5.4 kernel has no zte-ldoN LEDs: ZTE's zte_ldo_leds switches the same LDOs through vddcamaN_status for shell in self.each_shell():