]> git.lizzy.rs Git - rust.git/commitdiff
Support posix_spawn() for Linux glibc 2.24+.
authorBryan Drewery <bryan@shatow.net>
Fri, 2 Mar 2018 21:02:38 +0000 (13:02 -0800)
committerBryan Drewery <bryan@shatow.net>
Fri, 2 Mar 2018 21:08:04 +0000 (13:08 -0800)
The relevant support was added in https://sourceware.org/bugzilla/show_bug.cgi?id=10354#c12

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

index 51ae0aa73159accb6812a642381f0a25edbd689a..29e33ee822ee5b1f0473a8ba12c344e056e34476 100644 (file)
@@ -235,7 +235,8 @@ macro_rules! t {
         io::Error::last_os_error()
     }
 
-    #[cfg(not(any(target_os = "macos", target_os = "freebsd")))]
+    #[cfg(not(any(target_os = "macos", target_os = "freebsd",
+                  all(target_os = "linux", target_env = "gnu"))))]
     fn posix_spawn(&mut self, _: &ChildPipes, _: Option<&CStringArray>)
         -> io::Result<Option<Process>>
     {
@@ -244,7 +245,8 @@ fn posix_spawn(&mut self, _: &ChildPipes, _: Option<&CStringArray>)
 
     // Only support platforms for which posix_spawn() can return ENOENT
     // directly.
-    #[cfg(any(target_os = "macos", target_os = "freebsd"))]
+    #[cfg(any(target_os = "macos", target_os = "freebsd",
+              all(target_os = "linux", target_env = "gnu")))]
     fn posix_spawn(&mut self, stdio: &ChildPipes, envp: Option<&CStringArray>)
         -> io::Result<Option<Process>>
     {
@@ -258,6 +260,18 @@ fn posix_spawn(&mut self, stdio: &ChildPipes, envp: Option<&CStringArray>)
             return Ok(None)
         }
 
+        // Only glibc 2.24+ posix_spawn() supports returning ENOENT directly.
+        #[cfg(all(target_os = "linux", target_env = "gnu"))]
+        {
+            if let Some(version) = sys::os::glibc_version() {
+                if version < (2, 24) {
+                    return Ok(None)
+                }
+            } else {
+                return Ok(None)
+            }
+        }
+
         let mut p = Process { pid: 0, status: None };
 
         struct PosixSpawnFileActions(libc::posix_spawn_file_actions_t);