Skip to content

Commit 85b82f2

Browse files
committed
Support posix_spawn() for FreeBSD.
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.
1 parent b3ecf5f commit 85b82f2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/libstd/sys/unix/process/process_unix.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ impl Command {
235235
io::Error::last_os_error()
236236
}
237237

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

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

0 commit comments

Comments
 (0)