posix_spawn_file_actions_add[f]chdir_np

Corinna Vinschen corinna-cygwin@cygwin.com
Wed Apr 19 15:05:20 GMT 2023


Hi Bruno,

On Apr 19 13:24, Bruno Haible via Cygwin wrote:
> 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);

Ok, good to know.  I implemented it like glibc, so fd isn't tested in
posix_spawn_file_actions_addfchdir_np, but Austin group issue 1208 at
https://www.austingroupbugs.net/view.php?id=1208 documents it like it's
implemented in musl and FreeBSD:

  ERRORS
  The posix_spawn_file_actions_addfchdir( ) function shall fail if:
  [EBADF] The value specified by fildes is negative.
  [...]

I will fix this in Cygwin.

> > 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.)

I don't quite understand the snapshot thingy.  Can't you just run
setup in your Windows VM?

> It's easier
> for me to provide you a test case, with the unit tests from Gnulib.
> [...]
> 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.

Indeed, thanks a lot!  I checked all the above and ran the testsuite.
All tests pass except the test-posix_spawnp-script.exe testcase.
Great!


Thanks again,
Corinna


More information about the Cygwin mailing list