From 024f59b11867f267556eca5d71aed0e6a9f7a157 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Thu, 8 Feb 2024 09:59:17 -0500 Subject: [PATCH 1/2] posix_spawn: Fix inconsistency in macro name Previously the `configure` script would check for `posix_spawn_file_actions_addchdir` yet then the implementation would look for `HAVE_posix_spawn_file_actions_addchdir_np`. Fix this. --- cbits/posix/posix_spawn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cbits/posix/posix_spawn.c b/cbits/posix/posix_spawn.c index 32a8d838..39cb52d3 100644 --- a/cbits/posix/posix_spawn.c +++ b/cbits/posix/posix_spawn.c @@ -135,7 +135,7 @@ do_spawn_posix (char *const args[], } if (workingDirectory) { -#if defined(HAVE_posix_spawn_file_actions_addchdir_np) +#if defined(HAVE_posix_spawn_file_actions_addchdir) // N.B. this function is broken on macOS. // See https://github.com/rust-lang/rust/pull/80537. r = posix_spawn_file_actions_addchdir(&fa, workingDirectory); From e4b4638b1e88fb3a71a55da12819d98e5e7e33b9 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Thu, 8 Feb 2024 10:00:25 -0500 Subject: [PATCH 2/2] posix_spawn: Add support for posix_spawn_file_actions_addchdir_np It appears that glibc still has not introduced support for `posix_spawn_file_actions_addchdir`, despite it being ratified by Austin Group. Add support for `posix_spawn_file_actions_addchdir_np` as a stop-gap solution since the removal of the `vfork` path has turned up some pathological cases in the `fork` path in user code. --- cbits/posix/posix_spawn.c | 10 ++++++++-- configure.ac | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cbits/posix/posix_spawn.c b/cbits/posix/posix_spawn.c index 39cb52d3..af445837 100644 --- a/cbits/posix/posix_spawn.c +++ b/cbits/posix/posix_spawn.c @@ -136,13 +136,19 @@ do_spawn_posix (char *const args[], if (workingDirectory) { #if defined(HAVE_posix_spawn_file_actions_addchdir) - // N.B. this function is broken on macOS. - // See https://github.com/rust-lang/rust/pull/80537. r = posix_spawn_file_actions_addchdir(&fa, workingDirectory); if (r != 0) { *failed_doing = "posix_spawn_file_actions_addchdir"; goto fail; } +#elif defined(HAVE_posix_spawn_file_actions_addchdir_np) + // N.B. this function is broken on macOS. + // See https://github.com/rust-lang/rust/pull/80537. + r = posix_spawn_file_actions_addchdir_np(&fa, workingDirectory); + if (r != 0) { + *failed_doing = "posix_spawn_file_actions_addchdir_np"; + goto fail; + } #else goto not_supported; #endif diff --git a/configure.ac b/configure.ac index 23ec0702..59fb2e55 100644 --- a/configure.ac +++ b/configure.ac @@ -23,7 +23,7 @@ AC_CHECK_FUNCS([pipe2],[],[],[ # posix_spawn checks AC_CHECK_HEADERS([spawn.h]) -AC_CHECK_FUNCS([posix_spawnp posix_spawn_file_actions_addchdir],[],[],[ +AC_CHECK_FUNCS([posix_spawnp posix_spawn_file_actions_addchdir_np posix_spawn_file_actions_addchdir],[],[],[ #define _GNU_SOURCE #include ])