summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-06-08 14:18:46 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-06-08 14:30:07 -0400
commit8c130ca0117fd225c24569be2ec16c7dc2150a13 (patch)
tree56c682289d2393a4567d42d0effa31f564dc4b07
parent354c0adcf7edea2d036e35681610fc693a6796c0 (diff)
downloadbfs-8c130ca0117fd225c24569be2ec16c7dc2150a13.tar.xz
xspawn: Check X_OK even without $PATH resolution
Not all posix_spawn() implementations use errno to report execv() failures from the child process, as that requires either a kernel posix_spawn() implementation or a pipe to pass the error back. This should fix tests/posix/exec_nonexistent on OpenBSD and HPPA. Link: https://buildd.debian.org/status/fetch.php?pkg=bfs&arch=hppa&ver=3.3.1-1&stamp=1717489148&raw=0
-rw-r--r--src/xspawn.c13
-rw-r--r--tests/xspawn.c2
2 files changed, 13 insertions, 2 deletions
diff --git a/src/xspawn.c b/src/xspawn.c
index 33e5a4a..2c64011 100644
--- a/src/xspawn.c
+++ b/src/xspawn.c
@@ -426,8 +426,17 @@ static int bfs_resolve_early(struct bfs_resolver *res, const char *exe, const st
};
if (bfs_can_skip_resolve(res, ctx)) {
- res->done = true;
- return 0;
+ // Do this check eagerly, even though posix_spawn()/execv() also
+ // would, because:
+ //
+ // - faccessat() is faster than fork()/clone() + execv()
+ // - posix_spawn() is not guaranteed to report ENOENT
+ if (xfaccessat(AT_FDCWD, exe, X_OK) == 0) {
+ res->done = true;
+ return 0;
+ } else {
+ return -1;
+ }
}
res->path = getenv("PATH");
diff --git a/tests/xspawn.c b/tests/xspawn.c
index b1d6dc1..f48e220 100644
--- a/tests/xspawn.c
+++ b/tests/xspawn.c
@@ -179,6 +179,8 @@ static bool check_resolve(void) {
ret &= bfs_echeck(!bfs_spawn_resolve("eW6f5RM9Qi") && errno == ENOENT);
+ ret &= bfs_echeck(!bfs_spawn_resolve("bin/eW6f5RM9Qi") && errno == ENOENT);
+
return ret;
}