public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: CYGWIN=tty round 2
Date: Mon, 23 May 2011 15:40:00 -0000	[thread overview]
Message-ID: <20110523153944.GM3051@calimero.vinschen.de> (raw)
In-Reply-To: <BANLkTikxA97jxHkiOXr3DMNgTG4kr0o8uw@mail.gmail.com>

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

  reply	other threads:[~2011-05-23 15:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-22 21:19 Christopher Faylor
2011-05-23  2:53 ` Yaakov (Cygwin/X)
2011-05-23  6:02   ` Christopher Faylor
2011-05-23 17:27     ` Christopher Faylor
2011-05-23 11:49   ` Andy Koppe
2011-05-23 15:40     ` Corinna Vinschen [this message]
2011-05-23 23:21   ` Ryan Johnson
2011-05-24  6:22     ` Christopher Faylor
2011-05-24  9:54       ` Ryan Johnson
2011-05-23  9:36 ` Sven Köhler
2011-05-23 11:13   ` David Sastre
2011-05-23 21:24 Angelo Graziosi
2011-05-23 21:41 ` Fahlgren, Eric
2011-05-23 22:27 ` Christopher Faylor
2011-05-23 22:01 Angelo Graziosi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110523153944.GM3051@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).