Skip to content

Commit

Permalink
posix_spawn: Add support for posix_spawn_file_actions_addchdir_np
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bgamari committed Feb 8, 2024
1 parent 024f59b commit e4b4638
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions cbits/posix/posix_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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 <spawn.h>
])
Expand Down

0 comments on commit e4b4638

Please sign in to comment.