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: CYGWIN=tty round 2


On May 23 12:49, Andy Koppe wrote:
> The reason is that XWin.exe is built with -Wl,--subsystem,windows (or
> -mwindows, which implies it), which allows it to be invoked directly
> from a shortcut or the Run.. dialog without popping up a console or
> requiring a console hiding hack. (It's the same for mintty.)
> 
> The downside is that Windows also won't hook it up to the parent
> process's console, even if there is one, and hence there's nowhere for
> Cygwin to hook the standard file descriptors up to.
> 
> Having said that, XP introduced the AttachConsole() function, which
> allows hooking up to the parent's console by pasing
> 'ATTACH_PARENT_PROCESS' as the paremeter.

That doesn't work as expected.  I found that GetStdHandle does not
return INVALID_HANDLE_VALUE.  Rather, the handle looks like a normal
console handle.  Calling GetFileType then returns FILE_TYPE_UNKNOWN
and GetLastError () returns ERROR_INVALID_HANDLE.  I used that to
add this code:

Index: dtable.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/dtable.cc,v
retrieving revision 1.221
diff -u -p -r1.221 dtable.cc
--- dtable.cc	5 May 2011 22:30:53 -0000	1.221
+++ dtable.cc	23 May 2011 15:35:49 -0000
@@ -282,7 +282,10 @@ dtable::init_std_file_from_handle (int f
   char name[NT_MAX_PATH];
   name[0] = '\0';
   if (ft == FILE_TYPE_UNKNOWN && GetLastError () == ERROR_INVALID_HANDLE)
-    /* can't figure out what this is */;
+    {
+      if (AttachConsole (-1) || GetLastError () == ERROR_ACCESS_DENIED)
+	dev = *console_dev;
+    }
   else if (ft == FILE_TYPE_PIPE)
     {
       int rcv = 0, len = sizeof (int);

In thoery that should attach to the console and open the console
handles for stdin/out/err.

The effect:

- Started from CMD, XWin prints log output to the console.

- Started from bash or tcsh, no output.

- Mintty doesn't start at all.

That doesn't look overly promising.  It might be better if XWin itself
tries the AttachConsole/CreateFile("CONOUT$") thingy instead, otherwise
we might end up with some overly complex startup code(*) just for the
benefit of a single application.


Corinna


(*) Insert "which already is overly complex" here.

-- 
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]