Skip to content

Commit

Permalink
Support posix_spawn() for FreeBSD.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bdrewery committed Feb 28, 2018
1 parent b3ecf5f commit 85b82f2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/libstd/sys/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ impl Command {
io::Error::last_os_error()
}

#[cfg(not(any(target_os = "linux", target_os = "macos")))]
#[cfg(not(any(target_os = "freebsd")))]
fn posix_spawn(&mut self, _stdio: &ChildPipes, _envp: Option<&CStringArray>)
-> io::Result<Option<Process>>
{
Ok(None)
}

#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(any(target_os = "freebsd"))]
fn posix_spawn(&mut self, stdio: &ChildPipes, envp: Option<&CStringArray>)
-> io::Result<Option<Process>>
{
Expand Down

0 comments on commit 85b82f2

Please sign in to comment.