mirror of
https://github.com/MCKero6423/uv-k5-v3-emulator.git
synced 2026-10-02 11:07:31 +00:00
Two faults that combined to take the web UI down twice in one session, each time
surfacing to the user as a 502 through the reverse proxy.
`pkill -f 'M uv-k5-v3'` in run.sh and trace_run.sh matched far more than intended.
-f tests the whole command line, so it also matched the shell running the pkill
(the pattern sits in its own argv), any script mentioning the machine type, and the
QEMU child of a running webui.py. Cleanup now lives in tools/lib_kill_emulator.sh:
pgrep -x on the binary name, confirm uv-k5-v3 in /proc/PID/cmdline, and optionally
scope to one QMP socket so a caller only stops the instance it owns.
The supervisor then could not recover from it. power_on() began with
`if self._client is not None: return False`, but a client object is not proof of a
live guest -- after an external kill the stale client made power_on refuse forever,
so the Power button was dead until the whole service was restarted. It now checks
whether the process actually exited and relaunches, logging why.
Tests:
- tools/test_kill_emulator.sh checks a plain process, a process whose command line
merely mentions uv-k5-v3, and the calling script all survive; that a real emulator
on a named socket is stopped; that one on another socket is not; and that an
unscoped call still clears everything. Verified it leaves a live webui.py alone.
- Two supervisor unit tests cover relaunch-after-external-kill and the case that
must still refuse, so this cannot regress into starting two emulators at once.
Verified end to end against the running web UI: kill the emulator from outside,
status reports unreachable, and pressing Power brings it back to
{"status":"running"} where before it stayed dead.
While writing the first version of the test I modelled the failure as a client
raising BrokenPipeError, which is not what is_running() looks at -- it checks
poll(). The mock was wrong, not the code; the test now has the process report an
exit status, which is what really happens.
31 lines
986 B
Bash
Executable File
31 lines
986 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# Start the emulated radio.
|
|
#
|
|
# GDB stub : tcp:1234 (screenshot.py and where.sh read memory through it)
|
|
# QMP socket: /tmp/uvk5-qmp.sock (key.sh injects keypresses through it)
|
|
#
|
|
# Usage: run.sh [firmware.elf]
|
|
set -euo pipefail
|
|
|
|
QEMU="$HOME/qemu-build/qemu-7.2+dfsg/build/qemu-system-arm"
|
|
ELF="${1:-$HOME/uvk5-port/uvk5-sat/build/CW/nr7y.cw.elf}"
|
|
FLASH="$HOME/uvk5-port/sim/assets/flash.img"
|
|
QMP=/tmp/uvk5-qmp.sock
|
|
|
|
# Never `pkill -f 'M uv-k5-v3'` here: see tools/lib_kill_emulator.sh for why that
|
|
# takes down an unrelated webui.py along with it.
|
|
# shellcheck source=tools/lib_kill_emulator.sh
|
|
. "$(dirname "$0")/lib_kill_emulator.sh"
|
|
kill_emulators "$QMP"
|
|
rm -f "$QMP"
|
|
sleep 1
|
|
|
|
# Headless: the screen is read out of guest memory rather than drawn by QEMU, so
|
|
# no display backend is needed.
|
|
exec "$QEMU" \
|
|
-M "uv-k5-v3,flash-image=$FLASH" \
|
|
-nographic -monitor none \
|
|
-qmp "unix:$QMP,server=on,wait=off" \
|
|
-kernel "$ELF" \
|
|
-gdb tcp::1234
|