Skip to content

Rename dArkOS proxy process to survive game-end killall python3 cleanup - #54

Open
chrishaw wants to merge 2 commits into
misantronic:darkos-supportfrom
chrishaw:fix-darkos-proxy-killed-on-game-exit
Open

Rename dArkOS proxy process to survive game-end killall python3 cleanup#54
chrishaw wants to merge 2 commits into
misantronic:darkos-supportfrom
chrishaw:fix-darkos-proxy-killed-on-game-exit

Conversation

@chrishaw

Copy link
Copy Markdown

Summary

  • dArkOS's EmulationStation game-end hook runs sudo killall python3 on every game exit (confirmed via journalctl), which matches the proxy service by kernel process name since it runs as python3 -m raofflineproxy.main run-service.
  • Rename the process via prctl(PR_SET_NAME, ...) so it's no longer swept up by that cleanup command. Service discovery (discover_service_pids()) is unaffected since it matches on /proc/pid/cmdline, not comm.

Test plan

  • Confirmed on-device: ps -o pid,comm,args shows comm=raofflineproxy after the fix (previously python3)
  • Confirmed the proxy process survives launching and exiting a game on dArkOS, where it previously got killed every time

dArkOS's EmulationStation game-end hook runs `sudo killall python3` on
every game exit, which matches the proxy by kernel process name since
it runs as `python3 -m raofflineproxy.main run-service`. Rename the
process via prctl(PR_SET_NAME, ...) so it's no longer swept up.
@chrishaw

Copy link
Copy Markdown
Author

Disclosure: had AI help on this. Confirmed this works on R36S running dArkOSen-R36S

@misantronic misantronic left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will additionally add some github actions to automate test-runs for PRs

Comment thread linux/raofflineproxy/service.py Outdated
Addresses review comment: a libc without prctl left no trace when the
process-rename fallback failed.
comm, not argv/cgroup) don't kill the service by accident."""
try:
libc = ctypes.CDLL(None, use_errno=True)
libc.prctl(PR_SET_NAME, name.encode("utf-8"), 0, 0, 0)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctypes doesn't raise on a non-zero return value, so this except never catches an actual prctl() failure (only missing-symbol/load errors). The warning log added for the earlier comment still won't fire on a real syscall failure.

ret = libc.prctl(PR_SET_NAME, name.encode("utf-8"), 0, 0, 0)
if ret != 0:
    errno = ctypes.get_errno()
    logging.getLogger("raofflineproxy").warning(
        "Failed to rename process via prctl (errno=%s); comm name stays %r", errno, name
    )

Also, logging.getLogger("raofflineproxy") is now called in two places in this file, worth pulling into a module-level logger = logging.getLogger("raofflineproxy") and reusing it.

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.

2 participants