swiftlang / swiftlang/swift-subprocess
Allow spawning a process by file descriptor instead of path
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 734
- Forks
- 68
- Avg merge
- 9d 2h
- Merged PRs (30d)
- 6
Description
This would allow security conscious programs to have a more reliable spawn path that closes the inherent race condition in using paths.
execve for the fork/exec path is POSIX, and can be used by most platforms. FreeBSD 15.1 uniquely has new API for the posix_spawn based path: https://man.freebsd.org/cgi/man.cgi?query=posix_spawnattr_setexecfd_np&apropos=0&sektion=3&manpath=FreeBSD+16.0-CURRENT&format=html, while spawning by fd would have to force the fork/exec path for Linux/Android.
Windows has no way to launch a process given a fd or HANDLE, but in theory due to how the filesystem model works on Windows, we should be able to retrieve the underlying path of the HANDLE and pass that to CreateProcessW while still having greater guarantees, since an open handle locks the file for modifications.
macOS and OpenBSD don't support spawning a process by fd at all.
So I think we could reasonably enable such an API for FreeBSD/Linux/Android (via fd), and Windows (via fd and/or HANDLE).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing process-spawning entry points and the platform paths described in the issue: execve, FreeBSD's posix_spawnattr_setexecfd_np, and Windows CreateProcessW. Compare the fd and HANDLE capabilities across Linux, Android, FreeBSD, and Windows, and document which platforms can support the API; macOS and OpenBSD should remain unsupported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- backend-api-design, operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100