This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Rev 146953 seems not to work proper for mingw targets

Hi Kai,

On Wed, 13 May 2009 20:05:42 +0200
Kai Tietz <> wrote:

> Hello,
> the patch at
> breaks things for mingw target. I am a bit curious that you duplicate
> handles here (which is ok so far), but also close origin without
> checking for standard handles. The checks existing like
> ...
>   if (in != STDIN_FILENO)
>     _close (in);
>   if (out != STDOUT_FILENO)
> ...
> will close it always, because the _dup'ed handle will never have value
> STDIN_FILENO for sure. What is the intension of this patch? It looks a
> bit wired and wrong so far.

It cleared up an issue we were having where the child program blocked
forever after the parent died. It seems to be a fairly common problem
with pipes on win32, IIUC. I seem to have mangled the fix a bit

Can you try the attached patch (sorry, against an earlier version of
the patch in our tree, but the required changes are obvious) to see if
it works to fix your problem? It still seems to fix our original issue,




    * pex-win32.c (pex_win32_exec_child): Fix logic to avoid closing
    standard handles (stdin, stdout, stderr) in parent.
Index: libiberty/pex-win32.c
--- libiberty/pex-win32.c	(revision 249344)
+++ libiberty/pex-win32.c	(working copy)
@@ -753,17 +753,20 @@ pex_win32_exec_child (struct pex_obj *ob
      original descriptors.  */
   orig_in = in;
   in = _dup (orig_in);
-  obj->funcs->close (obj, orig_in);
+  if (orig_in != STDIN_FILENO)
+    obj->funcs->close (obj, orig_in);
   orig_out = out;
   out = _dup (orig_out);
-  obj->funcs->close (obj, orig_out);
+  if (orig_out != STDOUT_FILENO)
+    obj->funcs->close (obj, orig_out);
   if (separate_stderr)
       orig_err = errdes;
       errdes = _dup (orig_err);
-      obj->funcs->close (obj, orig_err);
+      if (orig_err != STDERR_FILENO)
+	obj->funcs->close (obj, orig_err);
   stdin_handle = INVALID_HANDLE_VALUE;
@@ -844,12 +847,10 @@ pex_win32_exec_child (struct pex_obj *ob
   /* Close the standard input, standard output and standard error handles
      in the parent.  */ 
-  if (in != STDIN_FILENO)
-    obj->funcs->close (obj, in);
-  if (out != STDOUT_FILENO)
-    obj->funcs->close (obj, out);
-  if (errdes != STDERR_FILENO)
-    obj->funcs->close (obj, errdes);
+  _close (in);
+  _close (out);
+  if (separate_stderr)
+    _close (errdes);
   return pid;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]