Skip to content

Commit

Permalink
posix_spawn: Don't attempt to dup2 identical fds
Browse files Browse the repository at this point in the history
macOS Big Sur does not allow the user to `posix_spawn_file_actions_adddup2` an
fd to itself. Instead of behaving as a no-op as specified by POSIX
2017.1 (and done by every other operating system), it instead fails with
`EBADFD` in `posix_spawn`. This caused a single tricky-to-identify
failure in GHC's testsuite.
  • Loading branch information
bgamari committed Jul 27, 2021
1 parent 110e7fe commit b6728c2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cbits/posix/posix_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ setup_std_handle_spawn (int fd,
return 0;

case STD_HANDLE_USE_FD:
if (posix_spawn_file_actions_adddup2(fa, hdl->use_fd, fd) != 0) {
*failed_doing = "posix_spawn_file_actions_adddup2";
return -1;
}
if (hdl->use_fd != fd) {
if (posix_spawn_file_actions_adddup2(fa, hdl->use_fd, fd) != 0) {
*failed_doing = "posix_spawn_file_actions_adddup2";
return -1;
}
}
return 0;

case STD_HANDLE_USE_PIPE:
Expand Down

0 comments on commit b6728c2

Please sign in to comment.