[PATCH] posix_spawn: preserve FD flags when processing FAE_OPEN

Jeremy Drake cygwin@jdrake.com
Wed Jul 9 17:52:14 GMT 2025


On Wed, 9 Jul 2025, Corinna Vinschen wrote:

> On Jul  8 15:51, Jeremy Drake wrote:
> > According to the POSIX documentation, "when the new process image is
> > executed, any file descriptor (from this new set) which has its
> > FD_CLOEXEC flag set shall be closed (see posix_spawn())."  The "new set"
> > is after processing the file actions, so if addopen had the O_CLOEXEC
> > flag set the descriptor should be closed after the exec.
> >
> > The adddup2 docs, by contrast, specify that the flag should be cleared,
> > even if dup2 wouldn't have done so due to the specified file descriptors
> > being equal.  Add a comment to that effect.
> >
> > Addresses: https://sourceware.org/pipermail/newlib/2025/021968.html
> > Fixes: c7c1a1ca1b ("2013-10-01  Petr Hosek  <phosek@chromium.org>")
> > Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
> > ---
> >  newlib/libc/posix/posix_spawn.c | 14 +++++++++++---
> >  1 file changed, 11 insertions(+), 3 deletions(-)
>
> LGTM. dup3 would be easier, but I'm not sure we can easily use it from
> within newlib, so, go ahead.

Pushed, along with the test in Cygwin's testsuite.



More information about the Newlib mailing list