-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Command: Support posix_spawn() on FreeBSD/OSX/GNU Linux #48624
Conversation
spawn() is expected to return an error if the specified file could not be executed. FreeBSD's posix_spawn() supports returning ENOENT/ENOEXEC if the exec() fails, which not all platforms support. This brings a very significant performance improvement for FreeBSD, involving heavy use of Command in threads, due to fork() invoking jemalloc fork handlers and causing lock contention. FreeBSD's posix_spawn() avoids this problem due to using vfork() internally.
FYI @alexcrichton, didn't assign you since you wrote the majority of the changes here. |
Nice! For posterity I originally didn't land this because it broke our test suite, notably the behavior of @bdrewery you were mentioning that a |
FreeBSD's
It's able to do this because of
This is intended and documented behavior.
|
Ah ok! I think I must have misunderstood then, that sounds perfect! @bors: r+ |
📌 Commit 85b82f2 has been approved by |
🌲 The tree is currently closed for pull requests below priority 200, this pull request will be tested once the tree is reopened |
Just for reference, those commits are contained in glibc-2.24. |
@cuviper is there a glibc function to call that returns the version? |
Yes, |
Oh nice catch @cuviper! I was testing locally with 2.23 when I initially wrote this, and I found that this program: use std::process::Command;
fn main() {
println!("{:?}", Command::new("nonexistent").spawn());
} where on today's standard library it prints an error but that's with running glibc 2.23 locally. Taking the same binary and running it with glibc 2.24 it prints an error (as today's rustc does). I haven't tested on OSX yet but sounds like we can certainly do this for Linux too! We'll just need to check at runtime that the version is >= 2.24. I also just tested with musl and it looks like they've implemented it in such a way (presumably the same way?) that prints an error as well, so on musl we can unconditionally use posix_spawn. |
@bdrewery would you be up for putting some of these checks in this PR? Or should I file a follow-up issue? |
@alexcrichton I had thought the command-exec.rs cases covered this but I see now they don't use |
It looks like I was just looking over OSX's opensource code and their
It seems like they based their implementation on NetBSD's. |
@bdrewery also to be clear I don't want to drag you into a bunch of portability nightmare scenarios, if you'd like to just do FreeBSD and be done with it that's perfectly ok! |
@alexcrichton yup understood, I don't mind looking at some of these right now. |
Tests pass on OSX for me so I've added support for it in, and fixed the error handling. Working on Linux support still. |
@bors: r+ Awesome, thanks! |
📌 Commit 8e0faf7 has been approved by |
…xcrichton Command: Support posix_spawn() on FreeBSD/OSX/GNU Linux
@bors r- The
|
@bors: r+ |
📌 Commit 70559c5 has been approved by |
…xcrichton Command: Support posix_spawn() on FreeBSD/OSX/GNU Linux
No description provided.