stdin and stdout were alreadly allowed for popen, but implementing
posix_spawn in terms of spawn would require stderr as well.
---
 winsup/cygwin/dcrt0.cc                    | 2 ++
 winsup/cygwin/local_includes/child_info.h | 6 +++---
 winsup/cygwin/spawn.cc                    | 5 +++--
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index f4c09befd6..9b02acf2cd 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -662,6 +662,8 @@ child_info_spawn::handle_spawn ()
     cygheap->fdtab.move_fd (__stdin, 0);
   if (__stdout >= 0)
     cygheap->fdtab.move_fd (__stdout, 1);
+  if (__stderr >= 0)
+    cygheap->fdtab.move_fd (__stderr, 2);
   cygheap->user.groups.clear_supp ();

   /* If we're execing we may have "inherited" a list of children forked by the
diff --git a/winsup/cygwin/local_includes/child_info.h 
b/winsup/cygwin/local_includes/child_info.h
index 2da62ffaa3..902be8727b 100644
--- a/winsup/cygwin/local_includes/child_info.h
+++ b/winsup/cygwin/local_includes/child_info.h
@@ -33,7 +33,7 @@ enum child_status
 #define EXEC_MAGIC_SIZE sizeof(child_info)

 /* Change this value if you get a message indicating that it is out-of-sync. */
-#define CURR_CHILD_INFO_MAGIC 0xacbf4682U
+#define CURR_CHILD_INFO_MAGIC 0x6ccb18aeU

 #include "pinfo.h"
 struct cchildren
@@ -145,7 +145,7 @@ public:
   cygheap_exec_info *moreinfo;
   int __stdin;
   int __stdout;
-  char filler[4];
+  int __stderr;

   void cleanup ();
   child_info_spawn () {};
@@ -190,7 +190,7 @@ public:
   bool has_execed_cygwin () const { return iscygwin () && has_execed (); }
   operator HANDLE& () {return hExeced;}
   int worker (const char *, const char *const *, const char *const [],
-                    int, int = -1, int = -1);
+                    int, int = -1, int = -1, int = -1);
 };

 extern child_info_spawn ch_spawn;
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index ef175e7082..9a7f0bbf73 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -281,7 +281,7 @@ extern DWORD mutex_timeout; /* defined in 
fhandler_termios.cc */
 int
 child_info_spawn::worker (const char *prog_arg, const char *const *argv,
                          const char *const envp[], int mode,
-                         int in__stdin, int in__stdout)
+                         int in__stdin, int in__stdout, int in__stderr)
 {
   bool rc;
   int res = -1;
@@ -517,6 +517,7 @@ child_info_spawn::worker (const char *prog_arg, const char 
*const *argv,
       set (chtype, real_path.iscygexec ());
       __stdin = in__stdin;
       __stdout = in__stdout;
+      __stderr = in__stderr;
       record_children ();

       si.lpReserved2 = (LPBYTE) this;
@@ -579,7 +580,7 @@ child_info_spawn::worker (const char *prog_arg, const char 
*const *argv,

       int fileno_stdin = in__stdin < 0 ? 0 : in__stdin;
       int fileno_stdout = in__stdout < 0 ? 1 : in__stdout;
-      int fileno_stderr = 2;
+      int fileno_stderr = in__stderr < 0 ? 2 : in__stderr;

       bool no_pcon = mode != _P_OVERLAY && mode != _P_WAIT;
       term_spawn_worker.setup (iscygwin (), handle (fileno_stdin, false),
-- 
2.49.0.windows.1

Reply via email to