diff --git a/openwrt/luci-app-mu300/root/usr/libexec/rpcd/mu300dash b/openwrt/luci-app-mu300/root/usr/libexec/rpcd/mu300dash index e17b93bd..bd242762 100755 --- a/openwrt/luci-app-mu300/root/usr/libexec/rpcd/mu300dash +++ b/openwrt/luci-app-mu300/root/usr/libexec/rpcd/mu300dash @@ -121,12 +121,12 @@ at_client_busy() { printf '%s\n' "$1" | grep -qxE '(mu300|unisoc)-at: busy'; } collecting() { _p=$(cat "$COLLECT_LCK/pid" 2>/dev/null) [ -n "$_p" ] && [ -d "/proc/$_p" ] && - tr '\0' ' ' < "/proc/$_p/cmdline" 2>/dev/null | grep -q '/unisoc-modem/cell' + { tr '\0' ' ' < "/proc/$_p/cmdline"; } 2>/dev/null | grep -q '/unisoc-modem/cell' } fast_busy() { _p=$(cat "$FAST_LCK/pid" 2>/dev/null) [ -n "$_p" ] && [ -d "/proc/$_p" ] && - tr '\0' ' ' < "/proc/$_p/cmdline" 2>/dev/null | grep -q '/unisoc-modem/cell' + { tr '\0' ' ' < "/proc/$_p/cmdline"; } 2>/dev/null | grep -q '/unisoc-modem/cell' } age_of() { [ -s "$1" ] && echo $(( $(now) - $(date -r "$1" +%s 2>/dev/null || echo 0) )) || echo -1; } diff --git a/openwrt/luci-app-mu300/root/usr/libexec/unisoc-modem/cell b/openwrt/luci-app-mu300/root/usr/libexec/unisoc-modem/cell index d8880f40..972ac1ad 100755 --- a/openwrt/luci-app-mu300/root/usr/libexec/unisoc-modem/cell +++ b/openwrt/luci-app-mu300/root/usr/libexec/unisoc-modem/cell @@ -89,7 +89,7 @@ qs() { json_str_or_null "$1"; } # --------------------------------------------------------------- one collector # the same "one owner, spare waits/takes over" pattern mu300-atd uses, so two # kicks (page reload while a refresh runs) cannot interleave AT replies -alive() { [ -n "$1" ] && [ -d "/proc/$1" ] && tr '\0' ' ' < "/proc/$1/cmdline" 2>/dev/null | grep -q '/unisoc-modem/cell'; } +alive() { [ -n "$1" ] && [ -d "/proc/$1" ] && { tr '\0' ' ' < "/proc/$1/cmdline"; } 2>/dev/null | grep -q '/unisoc-modem/cell'; } take_lock() { # take_lock DIRVAR - drop overlap, take over a dead holder local lock=$1 owner while ! mkdir "$lock" 2>/dev/null; do diff --git a/tests/test_static.py b/tests/test_static.py index c518dd9f..51692ad4 100644 --- a/tests/test_static.py +++ b/tests/test_static.py @@ -260,6 +260,20 @@ class Rules(unittest.TestCase): # and that its init works with Linux on either slot (mu300-update refuses one without it on slot a) self.assertIn(' tar -xzOf "$D/$a.tar.gz" ./features 2>/dev/null | grep -qx linux-slot', mr) + def test_proc_reads_are_braced(self): + # `tr < /proc/$pid/cmdline 2>/dev/null` reports a failed redirection (the process just went) before its own + # 2>/dev/null applies, so "can't open /proc/..." reaches the log: the read is braced, `{ tr < ...; } 2>/dev/null` + files = [p for p, _ in shell_scripts()] + files += [p for p in (TOP / 'openwrt' / 'luci-app-mu300' / 'root').rglob('*') + if p.is_file() and shebang(p).endswith('sh')] + bad = re.compile(r'<\s*"?/proc/\$[^\s;|]*\s+2>\s*/dev/null') + found = [] + for p in sorted(set(files)): + for n, line in enumerate(p.read_text(errors='replace').splitlines(), 1): + if bad.search(line): + found.append(f'{p.relative_to(TOP)}:{n}') + self.assertEqual(found, []) + def test_quiet_console_sysctl_on_both_systems(self): # K24: both images carry the same drop-in (systemd-sysctl on Ubuntu, procd's /etc/init.d/sysctl on OpenWrt) a = (TOP / 'rootfs' / 'overlay' / 'etc' / 'sysctl.d' / '99-mu300-console.conf').read_text()