It doesn't make a whole lot of sense to redirect stdin/out/err to/from a
directory handle, but test it anyway.

Signed-off-by: Jeremy Drake <cyg...@jdrake.com>
---
 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 c6ccc45fb2..0951d2d745 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 cd2bedcd95..8998c4337d 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));
-- 
2.49.0.windows.1

Reply via email to