[KERNEL32]: As indicated by the comment, kernel32 should always connect to the console server, even for non-console apps (the latter will just basically ignore the request). This is needed to (at minimum) setup the Ctrl-C handler, as otherwise, only "true console" apps will have a handler, even though internally, all apps have such a handler. This is what CSRSS needs to call internally for shutting down non-GUI apps, for example. (The default CTRL-C handler will just call ExitProcess).

svn path=/trunk/; revision=46047
This commit is contained in:
Sir Richard 2010-03-10 03:32:17 +00:00
parent e6baa6f072
commit cbe3e09f61
2 changed files with 37 additions and 33 deletions

View file

@ -39,6 +39,7 @@ BOOL
WINAPI
DefaultConsoleCtrlHandler(DWORD Event)
{
DPRINT1("Default handler called: %lx\n", Event);
switch(Event)
{
case CTRL_C_EVENT:
@ -76,6 +77,7 @@ ConsoleControlDispatcher(DWORD CodeAndFlag)
UINT i;
EXCEPTION_RECORD erException;
DPRINT1("Console Dispatcher Active: %lx %lx\n", CodeAndFlag, nCode);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
switch(nCode)
@ -152,6 +154,7 @@ ConsoleControlDispatcher(DWORD CodeAndFlag)
(CodeAndFlag & MINLONG) &&
((nCode == CTRL_LOGOFF_EVENT) || (nCode == CTRL_SHUTDOWN_EVENT)))
{
DPRINT1("Skipping system/service apps\n");
break;
}
@ -172,7 +175,6 @@ ConsoleControlDispatcher(DWORD CodeAndFlag)
}
RtlLeaveCriticalSection(&ConsoleLock);
ExitThread(nExitCode);
}

View file

@ -128,6 +128,7 @@ BasepInitConsole(VOID)
CSR_API_MESSAGE Request;
ULONG CsrRequest;
NTSTATUS Status;
BOOLEAN NotConsole = FALSE;
PRTL_USER_PROCESS_PARAMETERS Parameters = NtCurrentPeb()->ProcessParameters;
WCHAR lpTest[MAX_PATH];
@ -143,9 +144,10 @@ BasepInitConsole(VOID)
{
DPRINT("Image is not a console application\n");
Parameters->ConsoleHandle = NULL;
return TRUE;
Request.Data.AllocConsoleRequest.ConsoleNeeded = FALSE;
}
else
{
/* Assume one is needed */
Request.Data.AllocConsoleRequest.ConsoleNeeded = TRUE;
@ -177,6 +179,7 @@ BasepInitConsole(VOID)
}
DPRINT("Using existing console: %x\n", Parameters->ConsoleHandle);
}
}
/* Initialize Console Ctrl Handler */
ConsoleInitialized = TRUE;
@ -194,9 +197,6 @@ BasepInitConsole(VOID)
* but we don't have one yet, so we will instead simply send a create
* console message to the Base Server. When we finally have a Console
* Server, this code should be changed to send connection data instead.
*
* Also note that this connection should be made for any console app, even
* in the case above where -we- return.
*/
CsrRequest = MAKE_CSR_API(ALLOC_CONSOLE, CSR_CONSOLE);
Request.Data.AllocConsoleRequest.CtrlDispatcher = ConsoleControlDispatcher;
@ -211,6 +211,8 @@ BasepInitConsole(VOID)
return TRUE;
}
if (NotConsole) return TRUE;
/* We got the handles, let's set them */
if ((Parameters->ConsoleHandle = Request.Data.AllocConsoleRequest.Console))
{