feat(libc): support daemon on POSIX hosts #10453

Closed
MarcZX10 wants to merge 1 commit from upstream-pr/10453 into main
MarcZX10 commented 2026-10-24 01:14:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T01:14:52Z.


What

Forward daemon to the host implementation on POSIX systems. Preserve the explicit unsupported error on Windows, where the running guest process cannot be detached using POSIX fork semantics. Add subprocess coverage for all nochdir/noclose combinations, checking session detachment, working directory, and standard descriptors. The behavior follows the fork/session/directory/descriptor contract shown in FreeBSD libc and OpenBSD libc; console behavior is not verified.

Tested

  • Linux host: compiled the changed Process.cpp and GuestDaemon.cpp, linked the actual objects with section garbage collection, and ran GuestDaemon three times. All four flag combinations passed.
  • MinGW-w64: syntax-checked both changed C++ files.
  • python3 tools/check_conventions.py --base upstream/main --head HEAD passed.
  • git diff --check passed.
  • Not tested: full product build, macOS runtime, Windows runtime, or console behavior. The worktree's third-party submodules are not initialized, so the full project build was unavailable locally.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4991301716 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10453). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T01:14:52Z. --- ### What Forward `daemon` to the host implementation on POSIX systems. Preserve the explicit unsupported error on Windows, where the running guest process cannot be detached using POSIX `fork` semantics. Add subprocess coverage for all `nochdir`/`noclose` combinations, checking session detachment, working directory, and standard descriptors. The behavior follows the fork/session/directory/descriptor contract shown in [FreeBSD libc](https://github.com/freebsd/freebsd-src/blob/main/lib/libc/gen/daemon.c) and [OpenBSD libc](https://github.com/openbsd/src/blob/master/lib/libc/gen/daemon.c); console behavior is not verified. ### Tested - Linux host: compiled the changed `Process.cpp` and `GuestDaemon.cpp`, linked the actual objects with section garbage collection, and ran `GuestDaemon` three times. All four flag combinations passed. - MinGW-w64: syntax-checked both changed C++ files. - `python3 tools/check_conventions.py --base upstream/main --head HEAD` passed. - `git diff --check` passed. - Not tested: full product build, macOS runtime, Windows runtime, or console behavior. The worktree's third-party submodules are not initialized, so the full project build was unavailable locally. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
harisibrar1 commented 2026-10-24 05:01:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T05:01:36Z.

Review: COMMENTED


Checked against main 6c52b649e7 and FreeBSD 11.4 lib/libc/gen/daemon.c:

  • Forwarding to host ::daemon makes the emulator's own process _exit(0) (FreeBSD daemon.c does the same in the parent), and the guest continues in a child that has only the calling thread. The other guest threads and the render, audio and input threads don't exist there, and any lock they held stays locked. The emulator's shutdown callbacks never run, and with noclose == 0 its logs go to /dev/null. The new test forks a single-threaded helper first, so it can't show this. Could the debt entry describe it, or better, could daemon keep throwing like fork (libkernel_sys/Export.cpp:322)?
  • chdir("/") happens on the host, but the guest working directory is emulated (General.cpp:268-276, getcwd_nid_postfix at :788). After daemon(0, 1), a guest getcwd() still returns the previous directory, where FreeBSD returns "/".
  • On failure the host errno reaches the guest unchanged, while other forwards translate it with GuestErrnoFromHost_nid_no_patch. For example, a Linux fork EAGAIN (11) reads as EDEADLK in FreeBSD numbering (FreeBSD's EAGAIN is 35).
  • Main makes setsid fail with EPERM and fork throw, and the PPSA85300 port cited in debt/libkernel.md stubs fork/vfork with ENOSYS, which suggests a console daemon() fails rather than detaches. With no title calling it (the debt notes VLC needs --daemon), keeping the throw seems closer to the project rules than a host success.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636927002 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10453#pullrequestreview-5636927002). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T05:01:36Z. **Review:** COMMENTED --- Checked against main 6c52b649e7 and FreeBSD 11.4 lib/libc/gen/daemon.c: - Forwarding to host `::daemon` makes the emulator's own process `_exit(0)` (FreeBSD daemon.c does the same in the parent), and the guest continues in a child that has only the calling thread. The other guest threads and the render, audio and input threads don't exist there, and any lock they held stays locked. The emulator's shutdown callbacks never run, and with `noclose == 0` its logs go to `/dev/null`. The new test forks a single-threaded helper first, so it can't show this. Could the debt entry describe it, or better, could `daemon` keep throwing like `fork` (libkernel_sys/Export.cpp:322)? - `chdir("/")` happens on the host, but the guest working directory is emulated (General.cpp:268-276, `getcwd_nid_postfix` at :788). After `daemon(0, 1)`, a guest `getcwd()` still returns the previous directory, where FreeBSD returns "/". - On failure the host errno reaches the guest unchanged, while other forwards translate it with `GuestErrnoFromHost_nid_no_patch`. For example, a Linux `fork` EAGAIN (11) reads as EDEADLK in FreeBSD numbering (FreeBSD's EAGAIN is 35). - Main makes `setsid` fail with EPERM and `fork` throw, and the PPSA85300 port cited in debt/libkernel.md stubs `fork`/`vfork` with ENOSYS, which suggests a console `daemon()` fails rather than detaches. With no title calling it (the debt notes VLC needs `--daemon`), keeping the throw seems closer to the project rules than a host success. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10453
No description provided.