https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=a4c2540d0facec45ece3e754851616ade85caeb8

commit a4c2540d0facec45ece3e754851616ade85caeb8
Author: Jeremy Drake <cyg...@jdrake.com>
Date:   Thu Jun 26 10:14:34 2025 -0700

    Cygwin: testsuite: test passing directory fd to child
    
    This is a legal (if non-obvious) thing to do, so test it.
    
    Signed-off-by: Jeremy Drake <cyg...@jdrake.com>

Diff:
---
 winsup/testsuite/winsup.api/posix_spawn/chdir.c | 12 ++++++++++++
 winsup/testsuite/winsup.api/posix_spawn/win32.c | 11 +++++++++++
 2 files changed, 23 insertions(+)

diff --git a/winsup/testsuite/winsup.api/posix_spawn/chdir.c 
b/winsup/testsuite/winsup.api/posix_spawn/chdir.c
index c6ccc45fb..0951d2d74 100644
--- a/winsup/testsuite/winsup.api/posix_spawn/chdir.c
+++ b/winsup/testsuite/winsup.api/posix_spawn/chdir.c
@@ -140,6 +140,18 @@ int main (int argc, char **argv)
   negError (waitpid (pid, &status, 0));
   exitStatus (status, 0);
   errCode (posix_spawn_file_actions_destroy (&fa));
+
+  /* test posix_spawn_file_actions_addfchdir + adddup2 of directory fd */
+  errCode (posix_spawn_file_actions_init (&fa));
+  errCode (posix_spawn_file_actions_adddup2 (&fa, fd, 0));
+  errCode (posix_spawn_file_actions_addfchdir_np (&fa, fd));
+  errCode (posix_spawn_file_actions_addopen (&fa, 1, "tmpfile2", O_WRONLY, 
0644));
+  childargv[3] = buf;
+  errCode (posix_spawn (&pid, MYSELF, &fa, NULL, childargv, environ));
+  negError (waitpid (pid, &status, 0));
+  exitStatus (status, 0);
+  errCode (posix_spawn_file_actions_destroy (&fa));
+
   negError (close (fd));
 
   return 0;
diff --git a/winsup/testsuite/winsup.api/posix_spawn/win32.c 
b/winsup/testsuite/winsup.api/posix_spawn/win32.c
index cd2bedcd9..8998c4337 100644
--- a/winsup/testsuite/winsup.api/posix_spawn/win32.c
+++ b/winsup/testsuite/winsup.api/posix_spawn/win32.c
@@ -162,6 +162,17 @@ int main (void)
   errCode (posix_spawn_file_actions_destroy (&fa));
   free (childargv[2]);
 
+  /* test posix_spawn_file_actions_adddup2 of directory handle */
+  errCode (posix_spawn_file_actions_init (&fa));
+  errCode (posix_spawn_file_actions_adddup2 (&fa, cwdfd, 0));
+  childargv[1] = "0";
+  childargv[2] = cygwin_create_path (CCP_POSIX_TO_WIN_A|CCP_ABSOLUTE, tmpcwd);
+  errCode (posix_spawn (&pid, winchild, &fa, NULL, childargv, environ));
+  negError (waitpid (pid, &status, 0));
+  exitStatus (status, 0);
+  errCode (posix_spawn_file_actions_destroy (&fa));
+  free (childargv[2]);
+
   negError (close (cwdfd));
   negError (close (fd));
   negError (close (fdcloexec));

Reply via email to