diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2025-06-15 13:30:42 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2025-06-15 13:30:52 -0400 |
commit | 8a933df2e2a842dc9fffc6a2fa56b3d3836a3089 (patch) | |
tree | 36066561c75f2441c80f8e407a8d595a84e1a0e6 /src | |
parent | 134aa5d1c0bc71ec6cbf8f18f803976d6b60b0cc (diff) | |
download | bfs-8a933df2e2a842dc9fffc6a2fa56b3d3836a3089.tar.xz |
xspawn: Work around a macOS posix_spawn() bug
The XNU posix_spawn() implementation apparently can't handle fchdir() to
a directory opened by the file actions themselves.
Diffstat (limited to 'src')
-rw-r--r-- | src/xspawn.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/xspawn.c b/src/xspawn.c index 7ead45a..cf31cc9 100644 --- a/src/xspawn.c +++ b/src/xspawn.c @@ -243,6 +243,17 @@ int bfs_spawn_addfchdir(struct bfs_spawn *ctx, int fd) { return -1; } +#if __APPLE__ + // macOS has a bug that causes EBADF when an fchdir() action refers to a + // file opened by the file actions + for_slist (struct bfs_spawn_action, action, ctx) { + if (fd == action->out_fd) { + bfs_spawn_clear_posix(ctx); + break; + } + } +#endif + #if BFS_HAS_POSIX_SPAWN_ADDFCHDIR # define BFS_POSIX_SPAWN_ADDFCHDIR posix_spawn_file_actions_addfchdir #elif BFS_HAS_POSIX_SPAWN_ADDFCHDIR_NP |