diff options
| author | Rain <rain@sunshowers.io> | 2022-08-19 18:24:21 -0700 |
|---|---|---|
| committer | Rain <rain@sunshowers.io> | 2022-08-28 19:31:09 -0700 |
| commit | bd8b4b9c1588f0c681162ead34cc91b3f9a52bfc (patch) | |
| tree | 430ce7b689a015dc36c2f1cc4fe731a162ff4a41 /library/std/src/sys/unix/process/process_unix.rs | |
| parent | 1ea4efd0656599f824e2567a5b7a95454f701c03 (diff) | |
| download | rust-bd8b4b9c1588f0c681162ead34cc91b3f9a52bfc.tar.gz rust-bd8b4b9c1588f0c681162ead34cc91b3f9a52bfc.zip | |
Use posix_spawn for absolute paths on macOS
Currently, on macOS, Rust never uses the fast posix_spawn path if a directory change is requested due to a bug in Apple's libc. However, the bug is only triggered if the program is a relative path. This PR makes it so that the fast path continues to work if the program is an absolute path or a lone filename. This was an alternative proposed in https://github.com/rust-lang/rust/pull/80537#issue-776674009, and it makes a measurable performance difference in some of my code that spawns thousands of processes.
Diffstat (limited to 'library/std/src/sys/unix/process/process_unix.rs')
| -rw-r--r-- | library/std/src/sys/unix/process/process_unix.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs index 75bb92437fd..26ae6281771 100644 --- a/library/std/src/sys/unix/process/process_unix.rs +++ b/library/std/src/sys/unix/process/process_unix.rs @@ -453,7 +453,9 @@ impl Command { // successfully launch the program, but erroneously return // ENOENT when used with posix_spawn_file_actions_addchdir_np // which was introduced in macOS 10.15. - return Ok(None); + if self.get_program_kind() == ProgramKind::Relative { + return Ok(None); + } } match posix_spawn_file_actions_addchdir_np.get() { Some(f) => Some((f, cwd)), |
