mirror of
https://github.com/dikeckaan/mu300-linux.git
synced 2026-12-06 00:03:00 +00:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DqKKtBQZCfxYnHuBCuDqqn
This commit is contained in:
1 parent
7e429273f9
commit
cb3008096b
6 files changed
+18
-8
No files matched your search
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in new issue
Block a user