Skip to content

Commit

Permalink
xspawn: Check X_OK even without $PATH resolution
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tavianator committed Jun 8, 2024
1 parent 354c0ad commit 8c130ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/xspawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions tests/xspawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 8c130ca

Please sign in to comment.