Use posix_spawn instead of vfork + exec#2800
Merged
sporksmith merged 3 commits intoshadow:mainfrom Mar 24, 2023
Merged
Conversation
Contributor
Author
|
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
Contributor
Author
|
Given that this is a relatively risky change, I'll hold off on merging until after the upcoming stable release. |
stevenengler
approved these changes
Mar 24, 2023
Contributor
stevenengler
left a comment
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_spawnbasically does that for us already.