Skip to content

rocknix: runemu.sh returns how the launch ended - #3286

Open
maxengel wants to merge 1 commit into
ROCKNIX:nextfrom
maxengel:pr/launch-exit-status
Open

maxengel wants to merge 1 commit into
ROCKNIX:nextfrom
maxengel:pr/launch-exit-status

Conversation

@maxengel

@maxengel maxengel commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

What

wait_lock() in profile.d/001-functions installs

trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT

On EXIT the trap runs rm (status 0) and then re-exits with rm's status, so every script that has taken the settings lock exits 0 however it ended. runemu.sh takes it (cooling profile, netplay mode), so its quit 1 after a failed launch reaches EmulationStation as 0 — a RetroArch Failed to load content looked like a clean exit. $lockfile is also never assigned anywhere, so the trap never removed the lock it was there to release: a script killed while holding it left /tmp/.system.cfg.lock behind and later set_setting calls spun forever.

Fix

  • Save $? first and exit with it. Name the lock (J_CONF_LOCK) and remove it only when this shell still owns it: every caller releases the lock itself a few lines after taking it, the trap stays installed for the rest of the shell's life, and by the time a long-lived script like runemu.sh exits another process may hold the file. The EXIT arm stays for callers under set -e, where a failed sed inside del_setting exits with the lock held.
  • With the status reported for the first time, an emulator ended by the global exit hotkey (killall -9 → 137, SIGTERM → 143) would read as a failed launch — EmulationStation records play count and last-played only on 0. runemu.sh maps 137 and 143 to 0 with a log line; every other non-zero status still collapses to 1, leaving 200–300 for the messages EmulationStation can name.

Testing

On a GENERIC_X64 build: with a 64 KiB zero ROM, runemu.sh logged exiting with 1 and returned 0 before, 1 after; exit 7 while holding the lock returns 7 and releases it; a lock another pid owns at exit is left alone; TERM while holding returns 143 and releases it; set -e with a failed sed in del_setting returns 1 and releases the lock (was 0 with the lock left behind); a live RetroArch ended with SIGKILL returns 0. The same failed launch, driven through EmulationStation, reached the post-launch step as exit 1. Also running on two Anbernic H700 handhelds.

Known edge, left as is: RetroArch force-quit by the hotkey's SIGTERM exits 1 on its own, indistinguishable from a failed load.

No user-facing option or documentation changes.

wait_lock() installed

  trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT

On EXIT the trap ran rm (status 0) and then re-exited with rm's status,
so every script that had taken the settings lock exited 0 however it
ended. runemu.sh takes it for the cooling profile and netplay mode, so
its 'quit 1' after a failed launch reached EmulationStation as 0. And
$lockfile is never assigned anywhere, so the trap also never removed
the lock it was there to release: a script killed while holding it left
/tmp/.system.cfg.lock behind and every later set_setting spun forever.

Save $? first and exit with it. Name the lock (J_CONF_LOCK) and remove
it only when this shell still owns it: every caller releases the lock
itself a few lines after taking it, the trap stays installed for the
rest of the shell's life, and by the time a long-lived script such as
runemu.sh exits another process may hold the file. The EXIT arm stays
for callers under set -e, where a failed sed inside del_setting exits
with the lock held.

With the status reported for the first time, an emulator ended by the
global exit hotkey (killall -9 -> 137, SIGTERM -> 143) would read as a
failed launch: EmulationStation records play count, play time and
last-played only on 0. runemu.sh maps 137 and 143 to 0 with a log line;
every other non-zero status still collapses to 1, leaving 200-300 for
the messages EmulationStation can name.

Checked on a GENERIC_X64 guest: with a 64 KiB zero ROM runemu.sh logged
'exiting with 1' and returned 0 before, 1 after; exit 7 while holding
the lock returns 7 and releases it; a lock another pid owns at exit is
left alone; TERM while holding returns 143 and releases it; a live
RetroArch ended with SIGKILL returns 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant