This is the mail archive of the cygwin mailing list for the Cygwin 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: run: requires CYGWIN=tty?


On Nov 25 23:44, Charles Wilson wrote:
> Yaakov (Cygwin/X) wrote:
> > I came across this error with run when launched from the cmd prompt with
> > an empty CYGWIN variable:
> > 
> >      1 [main] xterm 1248 dtable::stdio_init: couldn't make stderr
> > distinct from stdout
> > 
> > If I set CYGWIN=tty then this does not occur.  Is this expected?
> 
> Not by me.  The relevant code in cygwin looks like this:
> [...]
>       if (!DuplicateHandle (hMainProc, out, hMainProc, &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");
>         }
> 
> So, uhm...DuplicateHandle failed? That seems...strange.  Unless the
> handle being duplicated is itself invalid.  (e.g. both out and err are
> == INVALID_HANDLE (but then, !not_open(2) should catch that!)
> 
> Maybe somebody else will have an A-HA! moment, but without actually
> debugging it this one has me confused.

DuplicateHandle() returns with ERROR_INVALID_PARAMETER.  A bit of
experimenting showed that it fails when using the duplicated process
handle hMainProc, but that it does not fail when using
GetCurrentProcess() instead.

So this works:

  DuplicateHandle (GetCurrentProcess (), out,
		   GetCurrentProcess (), &err,
		   0, true, DUPLICATE_SAME_ACCESS);

But this fails for some reason:

  DuplicateHandle (GetCurrentProcess (), GetCurrentProcess (),
		   GetCurrentProcess (), &hMainProc,
		   0, FALSE, DUPLICATE_SAME_ACCESS);
  DuplicateHandle (hMainProc, out,
		   hMainProc, &err,
		   0, true, DUPLICATE_SAME_ACCESS);

I will change that in Cygwin so that this code uses GetCurrentProcess ()
instead of hMainProc.

However, Chuck, can you please try the below patch to run.c instead?
It makes the stdout and stderr handles already distinct in run:

Index: src/run.c
===================================================================
RCS file: /cvs/cygwin-apps/run/src/run.c,v
retrieving revision 1.9
diff -u -p -r1.9 run.c
--- src/run.c	18 Aug 2009 15:51:05 -0000	1.9
+++ src/run.c	26 Nov 2009 09:33:11 -0000
@@ -418,7 +418,10 @@ BOOL configure_startupinfo(STARTUPINFO* 
       psi->hStdOutput  = CreateFile( "CONOUT$", GENERIC_WRITE | GENERIC_READ,
                          FILE_SHARE_WRITE, &sa,
                          OPEN_EXISTING, 0, 0 );
-      psi->hStdError   = psi->hStdOutput;
+      if (!DuplicateHandle (GetCurrentProcess (), psi->hStdOutput,
+			    GetCurrentProcess (), &psi->hStdError,
+			    0, TRUE, DUPLICATE_SAME_ACCESS))
+	psi->hStdError = psi->hStdOutput;
 
       Trace(("Have a console, and not requesting pipes: connecting child stdio to console"));
       return TRUE;


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


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