-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use posix_spawn instead of vfork + exec #2800
Conversation
A tor benchmark run shows no performance difference, as expected: https://github.com/shadow/benchmark-results/tree/master/tor/2023-03-22-T22-09-20 |
9b49f73
to
ab9b126
Compare
Given that this is a relatively risky change, I'll hold off on merging until after the upcoming stable release. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Hopefully this makes debugging easier as well.
Bare vfork + exec are tricky to use, since it's easy to accidentally corrupt the parent process's state from the child process. It's also unsupported in Rust (rust-lang/libc#1596). I think we could work around this in Rust by using inline assembly or a C helper function to wrap the fork and exec, but `posix_spawn` basically does that for us already.
* posix_spawn_file_actions_addchdir_np isn't present on older versions of glibc. Work around it by instead setting the working directory in the shim. * Older versions of glibc may use `fork` instead of `vfork` unless we explicitly request `vfork`. I'm not sure whether any of our supported platforms are affected by this or not, but it doesn't hurt to set it explicitly. * Older versions of glibc don't have a feature/hack that lets us use a single call to posix_spawn_file_actions_adddup2 with equal descriptor numbers to clear the O_CLOEXEC attribute. Use two calls to posix_spawn_file_actions_adddup2 instead, with a temporary descriptor number.
Bare vfork + exec are tricky to use, since it's easy to accidentally corrupt the parent process's state from the child process. It's also unsupported in Rust (rust-lang/libc#1574, rust-lang/libc#1596).
I think we could work around this in Rust by using inline assembly or a C helper function to wrap the fork and exec, but
posix_spawn
basically does that for us already.