On Wed, Nov 03, 2021 at 12:28:39PM +0000, Jonathan Perkin wrote:
* On 2021-11-03 at 11:49 GMT, David Brownlee wrote:
> Dumb question - could posix_spawn be used (and does it exhibit the same issue)?
Yeh it could, I discounted it as it has the same problems as system() (the
chdir() is being performed in the parent process), and I'm not convinced
it's very portable, but I could be wrong.
I added that implementation as a comment here:
https://gist.github.com/jperkin/6e66a8753ec8039b298cac7b57f2a7de#gistcomment-3949644
Try something like:
int old_cwd = open(".", O_RDONLY|O_CLOEXEC|O_DIRECTORY);
chdir(path);
posix_spawn(...);
fchdir(old_cwd);
Modulo error checking and defining O_CLOEXEC/O_DIRECTORY to 0 if they
don't exist.