Skip to content

Commit

Permalink
Support posix_spawn() for Linux glibc 2.24+.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdrewery committed Mar 2, 2018
1 parent 5ba6b3a commit d740083
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/libstd/sys/unix/process/process_unix.rs
Expand Up @@ -235,7 +235,8 @@ impl Command {
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>>
{
Expand All @@ -244,7 +245,8 @@ impl Command {

// 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>>
{
Expand All @@ -258,6 +260,18 @@ impl Command {
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);
Expand Down

0 comments on commit d740083

Please sign in to comment.