diff options
-rw-r--r-- | config/header.mk | 4 | ||||
-rw-r--r-- | config/posix-spawn-addfchdir-np.c | 11 | ||||
-rw-r--r-- | config/posix-spawn-addfchdir.c | 11 | ||||
-rw-r--r-- | config/prelude.mk | 2 | ||||
-rw-r--r-- | src/xspawn.c | 26 |
5 files changed, 32 insertions, 22 deletions
diff --git a/config/header.mk b/config/header.mk index 3a1271e..8867200 100644 --- a/config/header.mk +++ b/config/header.mk @@ -10,7 +10,9 @@ include config/exports.mk # All header fragments we generate HEADERS := \ ${GEN}/getprogname.h \ - ${GEN}/getprogname-gnu.h + ${GEN}/getprogname-gnu.h \ + ${GEN}/posix-spawn-addfchdir.h \ + ${GEN}/posix-spawn-addfchdir-np.h ${GEN}/config.h: ${HEADERS} ${MSG} "[ GEN] ${TGT}" diff --git a/config/posix-spawn-addfchdir-np.c b/config/posix-spawn-addfchdir-np.c new file mode 100644 index 0000000..b870a53 --- /dev/null +++ b/config/posix-spawn-addfchdir-np.c @@ -0,0 +1,11 @@ +// Copyright © Tavian Barnes <tavianator@tavianator.com> +// SPDX-License-Identifier: 0BSD + +#include <spawn.h> + +int main(void) { + posix_spawn_file_actions_t actions; + posix_spawn_file_actions_init(&actions); + posix_spawn_file_actions_addfchdir_np(&actions, 3); + return 0; +} diff --git a/config/posix-spawn-addfchdir.c b/config/posix-spawn-addfchdir.c new file mode 100644 index 0000000..c52ff81 --- /dev/null +++ b/config/posix-spawn-addfchdir.c @@ -0,0 +1,11 @@ +// Copyright © Tavian Barnes <tavianator@tavianator.com> +// SPDX-License-Identifier: 0BSD + +#include <spawn.h> + +int main(void) { + posix_spawn_file_actions_t actions; + posix_spawn_file_actions_init(&actions); + posix_spawn_file_actions_addfchdir(&actions, 3); + return 0; +} diff --git a/config/prelude.mk b/config/prelude.mk index 0ac5fde..b9bc61b 100644 --- a/config/prelude.mk +++ b/config/prelude.mk @@ -110,7 +110,7 @@ MSG = @msg() { \ msg # Maximum width of a short message, to align the [X] -MSG_WIDTH := 24 +MSG_WIDTH := 33 # cat a file if V=1 VCAT,y := @cat diff --git a/src/xspawn.c b/src/xspawn.c index 113d7ec..0b0cea4 100644 --- a/src/xspawn.c +++ b/src/xspawn.c @@ -212,7 +212,7 @@ int bfs_spawn_adddup2(struct bfs_spawn *ctx, int oldfd, int newfd) { * but macOS and NetBSD resolve the PATH *before* file_actions (because there * posix_spawn() is its own syscall). */ -#define BFS_POSIX_SPAWNP_AFTER_FCHDIR !(__APPLE__ || __NetBSD_Prereq__(10, 0, 0)) +#define BFS_POSIX_SPAWNP_AFTER_FCHDIR !(__APPLE__ || __NetBSD__) int bfs_spawn_addfchdir(struct bfs_spawn *ctx, int fd) { struct bfs_spawn_action *action = bfs_spawn_action(BFS_SPAWN_FCHDIR); @@ -220,29 +220,15 @@ int bfs_spawn_addfchdir(struct bfs_spawn *ctx, int fd) { return -1; } -#ifndef BFS_HAS_POSIX_SPAWN_FCHDIR -# define BFS_HAS_POSIX_SPAWN_FCHDIR __NetBSD_Prereq__(10, 0, 0) -#endif - -#ifndef BFS_HAS_POSIX_SPAWN_FCHDIR_NP -# if __GLIBC__ -# define BFS_HAS_POSIX_SPAWN_FCHDIR_NP __GLIBC_PREREQ(2, 29) -# elif __ANDROID__ -# define BFS_HAS_POSIX_SPAWN_FCHDIR_NP (__ANDROID_API__ >= 34) -# else -# define BFS_HAS_POSIX_SPAWN_FCHDIR_NP (__linux__ || __FreeBSD__ || __APPLE__) -# endif -#endif - -#if BFS_HAS_POSIX_SPAWN_FCHDIR -# define BFS_POSIX_SPAWN_FCHDIR posix_spawn_file_actions_addfchdir -#elif BFS_HAS_POSIX_SPAWN_FCHDIR_NP -# define BFS_POSIX_SPAWN_FCHDIR posix_spawn_file_actions_addfchdir_np +#if BFS_HAS_POSIX_SPAWN_ADDFCHDIR +# define BFS_POSIX_SPAWN_ADDFCHDIR posix_spawn_file_actions_addfchdir +#elif BFS_HAS_POSIX_SPAWN_ADDFCHDIR_NP +# define BFS_POSIX_SPAWN_ADDFCHDIR posix_spawn_file_actions_addfchdir_np #endif #if _POSIX_SPAWN > 0 && defined(BFS_POSIX_SPAWN_FCHDIR) if (ctx->flags & BFS_SPAWN_USE_POSIX) { - errno = BFS_POSIX_SPAWN_FCHDIR(&ctx->actions, fd); + errno = BFS_POSIX_SPAWN_ADDFCHDIR(&ctx->actions, fd); if (errno != 0) { free(action); return -1; |