]> git.lizzy.rs Git - rust.git/commitdiff
Support posix_spawn() for FreeBSD.
authorBryan Drewery <bryan@shatow.net>
Tue, 27 Feb 2018 22:12:52 +0000 (14:12 -0800)
committerBryan Drewery <bryan@shatow.net>
Wed, 28 Feb 2018 23:36:32 +0000 (15:36 -0800)
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.

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

index fa66245abb6d2c6772382337bdf9f9fb09138291..c7841a861ceb723a176269b6bf0ae22bcb6ec2dc 100644 (file)
@@ -235,14 +235,14 @@ macro_rules! t {
         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>>
     {