Cleanup: Use `posix_spawn()` in `_OS\fork_and_execve()` on MacOS
- Dominant language
- C++
- Stars
- 18.7k
- Forks
- 3.1k
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 2
Description
We currently do a pretty nasty trick to emulate `execvpe` on MacOS: https://github.com/facebook/hhvm/blob/ceb300a5bf2411b07f7907bd1a613583901b78b7/hphp/util/process.cpp#L644-L657
There's two ways we could clean this up:
- Set the Apple-specific `POSIX_SPAWN_SETEXEC` flag just to replace the execvp + _NSEnviron stuff call, keep the explicit fork (to share more code with the linux path)
- it looks like there's enough extensions now to implement all the fork_and_execve flags directly with `posix_spawn()` - we could replace the fork too
We /could/ also take option 2 on modern libcs.
I'm mostly filing this as a reminder. Perhaps we should take the first path now, but I think we should leave the second until there's a new enough libc on all supported linux distributions - we should continue sharing as much code as possible between the linux and macos paths to reduce the chance of platform-specific bugs or varying behavior.
Contributor guide
Research direction
Read hphp/util/process.cpp around lines 644-657 and compare the MacOS and Linux fork_and_execve paths. Determine whether to use POSIX_SPAWN_SETEXEC while retaining the fork or replace the fork as well; done means the selected approach preserves shared behavior and works across the supported platforms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- operating-systems
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100