From cb3008096bfe4afedcd00a9ee404448b098ab415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdurrahman=20Kaan=20Dike=C3=A7?= Date: Mon, 5 Oct 2026 17:44:20 +0300 Subject: [PATCH] mu300-at and its neighbours: a process gone from /proc no longer prints "can't open" into radio.log `tr < /proc/$pid/cmdline 2>/dev/null` reports a failed redirection before its own 2>/dev/null applies, so every check of a dead owner put "/opt/mu300/bin/mu300-at: line 96: can't open /proc/7668/cmdline" into mobile-data's radio.log lines (seen on both devices while the modem was down). The read is braced in mu300-at, mu300-atd, mobile-data, mu300-sms and mu300-smsd. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DqKKtBQZCfxYnHuBCuDqqn --- openwrt/luci-overlay/opt/mu300/bin/mu300-sms | 2 +- openwrt/luci-overlay/opt/mu300/bin/mu300-smsd | 2 +- rootfs/overlay/opt/mu300/bin/mobile-data | 4 ++-- rootfs/overlay/opt/mu300/bin/mu300-at | 6 +++--- rootfs/overlay/opt/mu300/bin/mu300-atd | 2 +- tests/test_device_scripts.py | 10 ++++++++++ 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/openwrt/luci-overlay/opt/mu300/bin/mu300-sms b/openwrt/luci-overlay/opt/mu300/bin/mu300-sms index cc4f4c46..cc81dd18 100755 --- a/openwrt/luci-overlay/opt/mu300/bin/mu300-sms +++ b/openwrt/luci-overlay/opt/mu300/bin/mu300-sms @@ -65,7 +65,7 @@ pool_init() { alive() { [ -n "$1" ] && kill -0 "$1" 2>/dev/null || return 1 [ -d /proc/self ] || return 0 - tr '\0' ' ' < "/proc/$1/cmdline" 2>/dev/null | grep -q "$2" + { tr '\0' ' ' < "/proc/$1/cmdline"; } 2>/dev/null | grep -q "$2" } # mkdir lock; a holder killed with SIGKILL leaves the directory behind, so a dead holder's lock is taken over diff --git a/openwrt/luci-overlay/opt/mu300/bin/mu300-smsd b/openwrt/luci-overlay/opt/mu300/bin/mu300-smsd index 53296128..2a90e341 100755 --- a/openwrt/luci-overlay/opt/mu300/bin/mu300-smsd +++ b/openwrt/luci-overlay/opt/mu300/bin/mu300-smsd @@ -27,7 +27,7 @@ LOCK=${MU300_SMS_LOCK:-/run/mu300-smsd.lock} alive() { [ -n "$1" ] && kill -0 "$1" 2>/dev/null || return 1 [ -d /proc/self ] || return 0 - tr '\0' ' ' < "/proc/$1/cmdline" 2>/dev/null | grep -q mu300-smsd + { tr '\0' ' ' < "/proc/$1/cmdline"; } 2>/dev/null | grep -q mu300-smsd } while ! mkdir "$LOCK" 2>/dev/null; do owner=$(cat "$LOCK/pid" 2>/dev/null || true) diff --git a/rootfs/overlay/opt/mu300/bin/mobile-data b/rootfs/overlay/opt/mu300/bin/mobile-data index a9d54c19..45866c8e 100755 --- a/rootfs/overlay/opt/mu300/bin/mobile-data +++ b/rootfs/overlay/opt/mu300/bin/mobile-data @@ -50,7 +50,7 @@ ATLOCK=/run/mu300-at/owner # pid into $ATLOCK/pid, and a bare pid says nothing once the number has been reused. at_owner_alive() { [ -n "${1:-}" ] && [ -d "/proc/$1" ] && - tr '\0' ' ' < "/proc/$1/cmdline" 2>/dev/null | grep -qE 'mu300-atd|mobile-data' + { tr '\0' ' ' < "/proc/$1/cmdline"; } 2>/dev/null | grep -qE 'mu300-atd|mobile-data' } at() { # at CMD [timeout] -> response lines up to the final result code @@ -356,7 +356,7 @@ lock_owner_alive() { [ -n "${1:-}" ] && kill -0 "$1" 2>/dev/null || return 1 # the number may have been reused by something else [ -r "/proc/$1/cmdline" ] || return 0 - tr '\0' ' ' < "/proc/$1/cmdline" 2>/dev/null | grep mobile-data >/dev/null + { tr '\0' ' ' < "/proc/$1/cmdline"; } 2>/dev/null | grep mobile-data >/dev/null } # lock_reap LINK DEADPID ME: remove LINK if it still names the dead process DEADPID. Only one process at a time may # do that for one (LINK, DEADPID): the one that makes the marker LINK.dead.DEADPID (made in one step, naming ME), and diff --git a/rootfs/overlay/opt/mu300/bin/mu300-at b/rootfs/overlay/opt/mu300/bin/mu300-at index 24387c9e..ddba299b 100755 --- a/rootfs/overlay/opt/mu300/bin/mu300-at +++ b/rootfs/overlay/opt/mu300/bin/mu300-at @@ -46,7 +46,7 @@ if [ -p "$DIR/cmd" ]; then if [ -n "$owner" ] && ! kill -0 "$owner" 2>/dev/null; then rm -rf "$lock" 2>/dev/null && continue # a daemon from before the split left its ownership directory here, and it will never release it - elif [ -n "$owner" ] && tr '\0' ' ' < "/proc/$owner/cmdline" 2>/dev/null | grep -q mu300-atd; then + elif [ -n "$owner" ] && { tr '\0' ' ' < "/proc/$owner/cmdline"; } 2>/dev/null | grep -q mu300-atd; then rm -rf "$lock" 2>/dev/null && continue fi n=$((n + 1)); [ "$n" -gt $((wait * 10)) ] && { echo "mu300-at: busy" >&2; exit 1; } @@ -93,7 +93,7 @@ if [ -p "$DIR/cmd" ]; then # exit within T + 2. budget=$((T + 2)) owner=$(cat "$DIR/owner/pid" 2>/dev/null || true) - if [ -n "$owner" ] && tr '\0' ' ' < "/proc/$owner/cmdline" 2>/dev/null | grep -q mu300-atd; then + if [ -n "$owner" ] && { tr '\0' ' ' < "/proc/$owner/cmdline"; } 2>/dev/null | grep -q mu300-atd; then budget=$((T + 30)) fi # MU300_AT_BUDGET (seconds) shortens that for a caller with a hard limit of its own (the LuCI panel: rpcd ends a @@ -126,7 +126,7 @@ fi # closing this channel while the modem is running leaves it silent until a reboot (FINDINGS 13b). owner=$(cat "$DIR/owner/pid" 2>/dev/null || true) if [ -n "$owner" ] && [ -d "/proc/$owner" ] && - tr '\0' ' ' < "/proc/$owner/cmdline" 2>/dev/null | grep -qE 'mu300-atd|mobile-data'; then + { tr '\0' ' ' < "/proc/$owner/cmdline"; } 2>/dev/null | grep -qE 'mu300-atd|mobile-data'; then echo "mu300-at: pid $owner holds $DEV and its command fifo is gone; restart mu300-atd" >&2 exit 1 fi diff --git a/rootfs/overlay/opt/mu300/bin/mu300-atd b/rootfs/overlay/opt/mu300/bin/mu300-atd index 12c9b0e9..ed37b4a5 100755 --- a/rootfs/overlay/opt/mu300/bin/mu300-atd +++ b/rootfs/overlay/opt/mu300/bin/mu300-atd @@ -48,7 +48,7 @@ mkdir -p "$DIR" # restart every client instead waited out its 90 s and printed "mu300-at: busy" over a completely idle channel. LOCK=$DIR/owner alive() { # alive PID -> is that pid still a running mu300-atd? - [ -n "$1" ] && [ -d "/proc/$1" ] && tr '\0' ' ' < "/proc/$1/cmdline" 2>/dev/null | grep -q mu300-atd + [ -n "$1" ] && [ -d "/proc/$1" ] && { tr '\0' ' ' < "/proc/$1/cmdline"; } 2>/dev/null | grep -q mu300-atd } while :; do if mkdir "$LOCK" 2>/dev/null; then break; fi diff --git a/tests/test_device_scripts.py b/tests/test_device_scripts.py index ff969c70..dd2f1329 100644 --- a/tests/test_device_scripts.py +++ b/tests/test_device_scripts.py @@ -100,6 +100,16 @@ class At(ShellTest): self.assertIn('no answer from the daemon', r.stderr) self.assertFalse((self.dir / 'lock').exists()) + def test_dead_owner_says_only_no_answer(self): + # owner/pid naming a process that is gone (the daemon died, or the modem never came up): the client says + # "no answer" and nothing else - mobile-data copies its stderr into radio.log + (self.dir / 'owner').mkdir() + (self.dir / 'owner' / 'pid').write_text('999999\n') + for shell in self.each_shell(): + r = self.at(shell, '-t', 1, 'AT') + self.assertEqual(r.returncode, 1) + self.assertEqual(r.stderr.strip(), 'mu300-at: no answer from the daemon', shell) + def test_command_survives_a_busy_daemon(self): # the daemon opens the FIFO only 0.5 s after the client wrote: the command must still be there for shell in self.each_shell():