Hi Corinna, > Actually I had some spare time yesterday so I came up with an > implementation of posix_spawn_file_actions_addchdir_np and > posix_spawn_file_actions_addfchdir_np. It's pretty straightforward: > > https://cygwin.com/cgit/newlib-cygwin/commit/?id=7e03fc35f528
Yes, it's pretty straightforward on Unix-like platforms. Note that there is a small inconsistency between implementations: The manual page https://man.freebsd.org/cgi/man.cgi?query=posix_spawn_file_actions_addfchdir_np&apropos=0&sektion=3&manpath=FreeBSD+13.2-RELEASE+and+Ports&arch=default&format=html mentions that when the dirfd argument is negative, the posix_spawn_file_actions_addfchdir function should fail with error EBADF. musl libc, FreeBSD, macOS do this; glibc doesn't. Test program attached below. Confirmed by looking at the source code: - musl libc: if (fd < 0) return EBADF; - FreeBSD: if (fildes < 0) return (EBADF); > You can install the just building test release > cygwin-3.5.0-0.287.g53f7fb20a064 via our installer, if you'd > like to test it. > > Actually... do you have a testcase readily available to share with us? Indeed, I'm not likely to install test releases. (Due to the way I work with my Windows VM, it's a bit clumsy to create a snapshot.) It's easier for me to provide you a test case, with the unit tests from Gnulib. I ran the command ./gnulib-tool --create-testdir --dir=../testdir-posix-spawn --single-configure \ posix_spawn \ posix_spawnattr_destroy \ posix_spawnattr_getflags \ posix_spawnattr_getpgroup \ posix_spawnattr_getschedparam \ posix_spawnattr_getschedpolicy \ posix_spawnattr_getsigdefault \ posix_spawnattr_getsigmask \ posix_spawnattr_init \ posix_spawnattr_setflags \ posix_spawnattr_setpgroup \ posix_spawnattr_setschedparam \ posix_spawnattr_setschedpolicy \ posix_spawnattr_setsigdefault \ posix_spawnattr_setsigmask \ posix_spawn_file_actions_addclose \ posix_spawn_file_actions_adddup2 \ posix_spawn_file_actions_addopen \ posix_spawn_file_actions_addchdir \ posix_spawn_file_actions_addfchdir \ posix_spawn_file_actions_destroy \ posix_spawn_file_actions_init \ posix_spawnp You can download the resulting tarball from https://haible.de/bruno/gnu/testdir-posix-spawn.tar.gz . When configuring it, set the environment variable gl_cv_func_posix_spawnp_secure_exec=yes . This will prevent the autoconfiguration from attempting to override the entire posix_spawn facility: $ env gl_cv_func_posix_spawnp_secure_exec=yes ./configure Verify through $ grep REPLACE_POSIX_SPAWN config.status that the values of REPLACE_POSIX_SPAWN and REPLACE_POSIX_SPAWNP are 0; if they are 1, the output of 'configure' should reveal why. Then build it: $ make Verify through $ ls -l gllib/*.o that no posix_spawn_*.o object file was built. Then run $ make check and it will run the unit tests against the Cygwin libc. It's likely that you will see 1 test failure (test-posix_spawnp-script); but other than that, there ought to be no test failures. Bruno ================ Test program for EBADF check ================ #include <spawn.h> int main (void) { posix_spawn_file_actions_t actions; if (posix_spawn_file_actions_init (&actions) != 0) return 1; if (posix_spawn_file_actions_addfchdir_np (&actions, -3) != 0) return 2; else return 3; } -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple