From 7bdbf062cdfe2978f75f80ff803e5e40d783557d Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Thu, 26 Nov 2009 10:58:06 +0000 Subject: [PATCH] * dtable.cc (dtable::stdio_init): Use GetCurrentProcess() rather than hMainProc as process handle when duplicating the stdout handle. Explain why. Add Win32 error code to debug output. --- winsup/cygwin/ChangeLog | 6 ++++++ winsup/cygwin/dtable.cc | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 2c9491345..923c5780a 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2009-11-26 Corinna Vinschen + + * dtable.cc (dtable::stdio_init): Use GetCurrentProcess() rather than + hMainProc as process handle when duplicating the stdout handle. + Explain why. Add Win32 error code to debug output. + 2009-11-23 Corinna Vinschen * fhandler_socket.cc (fhandler_socket::fixup_before_fork_exec): Add diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index 77055ef29..458e73f9e 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -177,12 +177,16 @@ dtable::stdio_init () { /* Since this code is not invoked for forked tasks, we don't have to worry about the close-on-exec flag here. */ - if (!DuplicateHandle (hMainProc, out, hMainProc, &err, 0, true, - DUPLICATE_SAME_ACCESS)) + /* CV 2009-11-26: Using hMainProc results in ERROR_INVALID_PARAMETER + when trying to duplicate a console handle. It only works using + the GetCurrentProcess () pseudo handle for some unknown reason. */ + if (!DuplicateHandle (GetCurrentProcess (), out, + GetCurrentProcess (), &err, + 0, TRUE, DUPLICATE_SAME_ACCESS)) { /* If that fails, do this as a fall back. */ err = out; - system_printf ("couldn't make stderr distinct from stdout"); + system_printf ("couldn't make stderr distinct from stdout, %E"); } }