Skip to content

Commit d740083

Browse files
committed
Support posix_spawn() for Linux glibc 2.24+.
The relevant support was added in https://sourceware.org/bugzilla/show_bug.cgi?id=10354#c12
1 parent 5ba6b3a commit d740083

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ impl Command {
235235
io::Error::last_os_error()
236236
}
237237

238-
#[cfg(not(any(target_os = "macos", target_os = "freebsd")))]
238+
#[cfg(not(any(target_os = "macos", target_os = "freebsd",
239+
all(target_os = "linux", target_env = "gnu"))))]
239240
fn posix_spawn(&mut self, _: &ChildPipes, _: Option<&CStringArray>)
240241
-> io::Result<Option<Process>>
241242
{
@@ -244,7 +245,8 @@ impl Command {
244245

245246
// Only support platforms for which posix_spawn() can return ENOENT
246247
// directly.
247-
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
248+
#[cfg(any(target_os = "macos", target_os = "freebsd",
249+
all(target_os = "linux", target_env = "gnu")))]
248250
fn posix_spawn(&mut self, stdio: &ChildPipes, envp: Option<&CStringArray>)
249251
-> io::Result<Option<Process>>
250252
{
@@ -258,6 +260,18 @@ impl Command {
258260
return Ok(None)
259261
}
260262

263+
// Only glibc 2.24+ posix_spawn() supports returning ENOENT directly.
264+
#[cfg(all(target_os = "linux", target_env = "gnu"))]
265+
{
266+
if let Some(version) = sys::os::glibc_version() {
267+
if version < (2, 24) {
268+
return Ok(None)
269+
}
270+
} else {
271+
return Ok(None)
272+
}
273+
}
274+
261275
let mut p = Process { pid: 0, status: None };
262276

263277
struct PosixSpawnFileActions(libc::posix_spawn_file_actions_t);

0 commit comments

Comments
 (0)