www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/11/26/04:35:25

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Thu, 26 Nov 2009 10:35:00 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: run: requires CYGWIN=tty?
Message-ID: <20091126093500.GA11956@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <4B0E0338 DOT 9000202 AT users DOT sourceforge DOT net> <4B0E07AC DOT 3020505 AT cwilson DOT fastmail DOT fm>
MIME-Version: 1.0
In-Reply-To: <4B0E07AC.3020505@cwilson.fastmail.fm>
User-Agent: Mutt/1.5.20 (2009-06-14)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019