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: [ANNOUNCEMENT] Updated: run-1.1.11-1


On Aug 16 12:55, Charles Wilson wrote:
> Colin Harrison wrote:
> > I am getting a stderr/pipe problem with some CUI's ~line 398 in run.c
> > (1.1.11 run + your patch)
> > bForceUsingPipes = (os_version >= 0x0501); 
> 
> #$!%#
> 
> > I made this = FALSE to fix for 2003 server..not tried on Windows 7.
> > I'm still testing (run built with MinGW) so this is maybe a clue or just a
> > bodge fix!
> > One failing CUI was plink (an ssh client from PuTTY).
> > 
> > I'll try and get back with more detail or a better fix!
> 
> I'd appreciate it.
> 
> I'm starting to suspect that there is no good mechanism to automatically
> DTRT here for [cygwin-1.5/cygwin-1.7/mingw] x
> [w95/98/Me/NT/2k/XP/Vista/Svr200x/W7] x [every app known to mankind],
> and that a command line option to override the internal heuristics may
> be required.  Don't you just love Windows?
> 
> FWIW, I've added run to the cygwin-apps repository, here:
> 
> cvs -z3 -d:pserver:anoncvs@cygwin.com:/cvs/cygwin-apps co run
> 
> but you'll need to 'autoreconf -fvi' before building it.

I had the idea to redirect to NUL: for the inferior process, so I
applied the below patch.  Don't ask for a reason, it was just a hunch
that this might work.

Redirecting to /dev/null works fine for me on W7.  With this patch, XWin
starts as expected when called from the `run startxwin.bat' shortcut,
xterm, gvim, xeyes all start fine, and, that's most interesting, urxvt
starts fine as well, without constantly taking 100% CPU.  And yes,
*this* time I made sure that the shortcut actually calls urxvt-X via
run.  In no case I have a flickering console window.

I'm not sure this a generic enough solution, there's probable more
necessary.  However, would others be so kind to test this on non-W7
systems as well as with other applications like emacs?

Btw., the patch also disables the calls to FreeConsole/AttachConsole on
W7 because they are useless, as I noted in one of my mails.


Corinna


	* run.c (configure_startupinfo): Open handles to "NUL:" and
	redirect child processes stdio handles to them if no pipes
	have to be set up.
	(start_child): Remove Windows 7 AttachConsole workaround.
	Set creation flag always to 0.  Set bForceUsingPipes always to
	FALSE unless in DEBUG_FORCE_PIPES mode.


Index: src/run.c
===================================================================
RCS file: /cvs/cygwin-apps/run/src/run.c,v
retrieving revision 1.8
diff -u -p -r1.8 run.c
--- src/run.c	16 Aug 2009 03:26:42 -0000	1.8
+++ src/run.c	17 Aug 2009 08:40:16 -0000
@@ -285,12 +285,13 @@ BOOL configure_startupinfo(STARTUPINFO* 
 
     ZeroMemory (psi, sizeof (STARTUPINFO));
     psi->cb = sizeof (STARTUPINFO);
-    psi->hStdInput   = GetStdHandle(STD_INPUT_HANDLE);
-    psi->hStdOutput  = GetStdHandle(STD_OUTPUT_HANDLE);
-    psi->hStdError   = GetStdHandle(STD_ERROR_HANDLE);
     psi->dwFlags     = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
     psi->wShowWindow = SW_HIDE;
 
+    handle_attrs.nLength = sizeof(SECURITY_ATTRIBUTES);
+    handle_attrs.bInheritHandle = TRUE;
+    handle_attrs.lpSecurityDescriptor = NULL;
+
     /* foo() is some magic mechanism for determining that the HANDLEs 
      * returned by GetStdHandle() are from a console, and not redirected
      * or ptys of some sort.  If we have such a mechanism, then the 
@@ -310,6 +311,16 @@ BOOL configure_startupinfo(STARTUPINFO* 
      */
     if (!bForceUsingPipes && bHaveInvisConsole)
     {
+	hpStdInput[0] = CreateFile ("NUL:", GENERIC_READ | GENERIC_WRITE,
+				    FILE_SHARE_VALID_FLAGS, &handle_attrs,
+				    OPEN_EXISTING, 0, NULL);
+	hpStdOutput[1] = CreateFile ("NUL:", GENERIC_READ | GENERIC_WRITE,
+				    FILE_SHARE_VALID_FLAGS, &handle_attrs,
+				    OPEN_EXISTING, 0, NULL);
+	psi->hStdInput   = hpStdInput[0];
+	psi->hStdOutput  = hpStdOutput[1];
+	psi->hStdError   = hpStdOutput[1];
+
        *bUsingPipes = FALSE;
        return TRUE;
     }
@@ -317,10 +328,6 @@ BOOL configure_startupinfo(STARTUPINFO* 
     /* otherwise, set up pipes */
     *bUsingPipes = TRUE;
 
-    handle_attrs.nLength = sizeof(SECURITY_ATTRIBUTES);
-    handle_attrs.bInheritHandle = TRUE;
-    handle_attrs.lpSecurityDescriptor = NULL;
-
     /* create a pipe for child's stdin.  Don't allow child to */
     /* inherit the write end of the pipe.                     */
     CreatePipe (&hpStdInput[0], &hpStdInput[1], &handle_attrs, 0);
@@ -353,34 +360,9 @@ int start_child(char* cmdline, int wait_
    BOOL bForceUsingPipes = FALSE;
    HANDLE hToChild, hFromChild;
    HANDLE hToParent, hFromParent;
-   BOOL WINAPI (*AttachConsoleFP)(DWORD) = NULL;
-   HWND WINAPI (*GetConsoleWindowFP)(VOID) = NULL;
-   DWORD creationFlags = 0;
 
    setup_win_environ();
 
-   /* Work around bug in Windows 7. For Vista and below, continue
-    * to use the more reliable setup_invisible_console() and its
-    * separate WindowStation approach; for W7 we need these pointers.
-    */
-   if (os_version >= 0x0601)
-     {
-       HMODULE lib = GetModuleHandle ("kernel32.dll");
-       AttachConsoleFP = (BOOL WINAPI (*)(DWORD))
-           GetProcAddress (lib, "AttachConsole");
-       GetConsoleWindowFP = (HWND WINAPI (*)(VOID))
-           GetProcAddress (lib, "GetConsoleWindow");
-       if (!AttachConsoleFP || !GetConsoleWindowFP)
-           os_version = 0;
-#if defined(__CYGWIN__) && HAVE_DECL_CYGWIN_CONV_PATH
-       /* and for cygwin-1.7, also this, because cygwin kernel
-        * will create a hidden console -- or attach child to an
-        * existing one -- for us.
-        */
-       /* creationFlags |= CREATE_NO_WINDOW; */
-#endif
-     }
-
 #ifdef DEBUG_FORCE_PIPES
    bHaveInvisConsole = FALSE;
    bForceUsingPipes = TRUE;
@@ -394,7 +376,7 @@ int start_child(char* cmdline, int wait_
    /* Fix issue with 100% CPU usage when launching certain apps from
     * a cmd.exe box
     */
-   bForceUsingPipes = (os_version >= 0x0501);
+   bForceUsingPipes = FALSE;
 #endif
 
    if (!configure_startupinfo(&start, bHaveInvisConsole,
@@ -414,7 +396,7 @@ int start_child(char* cmdline, int wait_
        NULL,    /* process security attributes         */
        NULL,    /* primary thread security attributes  */
        TRUE,    /* handles are inherited,              */
-       creationFlags, /* creation flags                */
+       0,	/* creation flags                */
        NULL,    /* use parent's environment            */
        NULL,    /* use parent's current directory      */
        &start,  /* STARTUPINFO pointer                 */
@@ -456,17 +438,6 @@ int start_child(char* cmdline, int wait_
           GetExitCodeProcess (child.hProcess, &retval);
       }
 
-      /* Work around bug in Windows 7. For Vista and below, continue
-       * to use the more reliable setup_invisible_console() and its
-       * separate WindowStation approach.
-       */
-      if (os_version >= 0x0601)
-      {
-        FreeConsole ();
-        (*AttachConsoleFP) (child.dwProcessId);
-        SetParent ((*GetConsoleWindowFP) (), HWND_MESSAGE);
-      }
-
       CloseHandle (child.hThread);
       CloseHandle (child.hProcess);
       if (bUsingPipes)

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