Skip to content

Commit f9b2f52

Browse files
committed
[illumos] attempt to use posix_spawn to spawn processes
illumos has `posix_spawn`, and the very newest versions also have `_addchdir`, so use that. This is a nice ~4x performance improvement for process creation. My go-to as usual is nextest against the clap repo, which acts as a stress test for process creation -- with [this commit]: ```console $ cargo nextest run -E 'not test(ui_tests) and not test(example_tests)' before: Summary [ 1.747s] 879 tests run: 879 passed, 2 skipped after: Summary [ 0.445s] 879 tests run: 879 passed, 2 skipped ``` [this commit]: clap-rs/clap@fde45f9
1 parent 85335cc commit f9b2f52

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ miniz_oxide = { version = "0.8.0", optional = true, default-features = false }
3535
addr2line = { version = "0.24.0", optional = true, default-features = false }
3636

3737
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
38-
libc = { version = "0.2.169", default-features = false, features = [
38+
libc = { version = "0.2.170", default-features = false, features = [
3939
'rustc-dep-of-std',
4040
], public = true }
4141

std/src/sys/pal/unix/process/process_unix.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ impl Command {
410410

411411
#[cfg(not(any(
412412
target_os = "freebsd",
413+
target_os = "illumos",
413414
all(target_os = "linux", target_env = "gnu"),
414415
all(target_os = "linux", target_env = "musl"),
415416
target_os = "nto",
@@ -427,6 +428,7 @@ impl Command {
427428
// directly.
428429
#[cfg(any(
429430
target_os = "freebsd",
431+
target_os = "illumos",
430432
all(target_os = "linux", target_env = "gnu"),
431433
all(target_os = "linux", target_env = "musl"),
432434
target_os = "nto",
@@ -584,14 +586,27 @@ impl Command {
584586
fn get_posix_spawn_addchdir() -> Option<PosixSpawnAddChdirFn> {
585587
use crate::sys::weak::weak;
586588

589+
// POSIX.1-2024 standardizes this function:
590+
// https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_spawn_file_actions_addchdir.html.
591+
// The _np version is more widely available, though, so try that first.
592+
587593
weak! {
588594
fn posix_spawn_file_actions_addchdir_np(
589595
*mut libc::posix_spawn_file_actions_t,
590596
*const libc::c_char
591597
) -> libc::c_int
592598
}
593599

594-
posix_spawn_file_actions_addchdir_np.get()
600+
weak! {
601+
fn posix_spawn_file_actions_addchdir(
602+
*mut libc::posix_spawn_file_actions_t,
603+
*const libc::c_char
604+
) -> libc::c_int
605+
}
606+
607+
posix_spawn_file_actions_addchdir_np
608+
.get()
609+
.or_else(|| posix_spawn_file_actions_addchdir.get())
595610
}
596611

597612
/// Get the function pointer for adding a chdir action to a

0 commit comments

Comments
 (0)