Skip to content

Commit

Permalink
xspawn: Use _PATH_DEFPATH if _CS_PATH is not defined
Browse files Browse the repository at this point in the history
And set errno correctly if neither one is.  Fixes
tests/posix/exec_nopath on Android.
  • Loading branch information
tavianator committed Nov 6, 2022
1 parent b7a222b commit 2724dfb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
# define BFS_HAS_MNTENT BFS_HAS_INCLUDE(<mntent.h>, __GLIBC__)
#endif

#ifndef BFS_HAS_PATHS
# define BFS_HAS_PATHS BFS_HAS_INCLUDE(<paths.h>, true)
#endif

#ifndef BFS_HAS_SYS_ACL
# define BFS_HAS_SYS_ACL BFS_HAS_INCLUDE(<sys/acl.h>, true)
#endif
Expand Down
12 changes: 10 additions & 2 deletions src/xspawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include <sys/wait.h>
#include <unistd.h>

#if BFS_HAS_PATHS
# include <paths.h>
#endif

/**
* Types of spawn actions.
*/
Expand Down Expand Up @@ -260,11 +264,15 @@ char *bfs_spawn_resolve(const char *exe) {
const char *path = getenv("PATH");

char *confpath = NULL;
#ifdef _CS_PATH
if (!path) {
#if defined(_CS_PATH)
path = confpath = xconfstr(_CS_PATH);
}
#elif defined(_PATH_DEFPATH)
path = _PATH_DEFPATH;
#else
errno = ENOENT;
#endif
}
if (!path) {
return NULL;
}
Expand Down

0 comments on commit 2724dfb

Please sign in to comment.