This is the mail archive of the cygwin-apps 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: New run version with patches for Windows 7


On Aug  9 11:21, Andy Koppe wrote:
> 2009/8/9 Corinna Vinschen:
> > Have you seen the patch? ?The code duplication is tiny. ?It's a much
> > simpler solution than in the Cygwin DLL.
> 
> But it'll still need changing again when MS break hidden consoles again.
> 
> > Having the console creation code in run also has the advantage of
> > working when starting run from an existing console window. ?The child
> > process will run detached from the existing console in an invisible
> > console window. ?You can close the original console afterwards without
> > killing the process ran through run.
> 
> That shouldn't be an issue. MSDN on FreeConsole(): "A console is
> closed when the last process attached to it terminates or calls
> FreeConsole."

Actually, it turned out that the entire FreeConsole/AttachConsole
stuff is entirely unnecessary.  I have a solution now which apparently
works for all OSes and it's really very simple.  What I didn't realize
is that run.exe as a GUI application has no console attached.  Thus,
only the child application started from run gets a hidden console 
created by Cygwin.  As a result there's some code unnecessary in
run.exe.  The child process gets now simply started without console
window at all, which in turn results in Cygwin creating the console for
the child.

New patch below.


Corinna


--- run-1.1.10.orig/src/run.c	2006-05-22 14:32:43.000000000 +0200
+++ run-1.1.10/src/run.c	2009-08-09 13:52:16.000000000 +0200
@@ -194,74 +194,6 @@ static void setup_win_environ(void)
         free(var);
     }
 }
-BOOL setup_invisible_console()
-{
-   HWINSTA h, horig;
-   USEROBJECTFLAGS oi;
-   DWORD len;
-   BOOL b = FALSE; 
-   HMODULE lib = NULL;
-   HWINSTA WINAPI (*GetProcessWindowStationFP)(void) = NULL;
-   BOOL WINAPI (*GetUserObjectInformationFP)(HANDLE, int, PVOID, DWORD, PDWORD) = NULL;
-   HWINSTA WINAPI (*CreateWindowStationFP)(LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES) = NULL;
-   BOOL WINAPI (*SetProcessWindowStationFP)(HWINSTA) = NULL;
-   BOOL WINAPI (*CloseWindowStationFP)(HWINSTA) = NULL;
-
-   /* until we have a mechanism of determining whether a given HANDLE 
-    * returned by GetStdHandles actually derives from a console, 
-    * unconditionally call FreeConsole() on all OSes under all conditions.
-    * See comments in configure_startupinfo(). 
-    */
-   FreeConsole();
-
-   /* First, set up function pointers */
-   if (lib = LoadLibrary ("user32.dll"))
-   {
-       GetProcessWindowStationFP = (HWINSTA WINAPI (*)(void))
-           GetProcAddress (lib, "GetProcessWindowStation");
-       GetUserObjectInformationFP = (BOOL WINAPI (*)(HANDLE, int, PVOID, DWORD, PDWORD))
-           GetProcAddress (lib, "GetUserObjectInformationW"); /* ugly! */
-       CreateWindowStationFP = (HWINSTA WINAPI (*)(LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES))
-           GetProcAddress (lib, "CreateWindowStationW"); /* ugly */
-       SetProcessWindowStationFP = (BOOL WINAPI (*)(HWINSTA))
-           GetProcAddress (lib, "SetProcessWindowStation");
-       CloseWindowStationFP = (BOOL WINAPI (*)(HWINSTA))
-           GetProcAddress (lib, "CloseWindowStation");
-
-       if (GetProcessWindowStationFP && 
-            GetUserObjectInformationFP &&
-            CreateWindowStationFP &&
-            SetProcessWindowStationFP &&
-            CloseWindowStationFP)
-       {
-           /* Then, do the work */
-           FreeConsole();
-           h = horig = (*GetProcessWindowStationFP)();
-           if (!horig 
-               || !(*GetUserObjectInformationFP) (horig, UOI_FLAGS, &oi, sizeof (oi), &len )
-               || !(oi.dwFlags & WSF_VISIBLE))
-           {
-               b = AllocConsole();
-           }
-           else
-           {
-               h = (*CreateWindowStationFP) (NULL, 0, STANDARD_RIGHTS_READ, NULL);
-               if (h)
-               {
-                   b = (*SetProcessWindowStationFP) (h);
-               }
-               b = AllocConsole();
-               if (horig && h && h != horig && (*SetProcessWindowStationFP) (horig))
-               {
-                   (*CloseWindowStationFP) (h);
-               }
-           }
-           return b;
-       }
-   }
-   /* otherwise, fail */ 
-   return FALSE;
-}
 
 /* returns FALSE only on error conditions (not impl) */
 BOOL configure_startupinfo(STARTUPINFO* psi, BOOL bHaveInvisConsole,
@@ -350,7 +282,7 @@ int start_child(char* cmdline, int wait_
    bHaveInvisConsole = FALSE;
    FreeConsole();
 #else
-   bHaveInvisConsole = setup_invisible_console();
+   bHaveInvisConsole = TRUE;
 #endif
 
    if (!configure_startupinfo(&start, bHaveInvisConsole,
@@ -366,15 +298,15 @@ int start_child(char* cmdline, int wait_
    ZeroMemory( &child, sizeof(PROCESS_INFORMATION) );
 
    bFuncReturn = CreateProcess (NULL,
-       cmdline, /* command line                        */
-       NULL,    /* process security attributes         */
-       NULL,    /* primary thread security attributes  */
-       TRUE,    /* handles are inherited,              */
-       0,       /* creation flags                      */
-       NULL,    /* use parent's environment            */
-       NULL,    /* use parent's current directory      */
-       &start,  /* STARTUPINFO pointer                 */
-       &child); /* receives PROCESS_INFORMATION        */
+       cmdline,          /* command line                        */
+       NULL,             /* process security attributes         */
+       NULL,             /* primary thread security attributes  */
+       TRUE,             /* handles are inherited,              */
+       CREATE_NO_WINDOW, /* creation flags                      */
+       NULL,             /* use parent's environment            */
+       NULL,             /* use parent's current directory      */
+       &start,           /* STARTUPINFO pointer                 */
+       &child);          /* receives PROCESS_INFORMATION        */
 
    if (bUsingPipes)
    {


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


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