- Fixed the initializing of the initial console control handler.

- Fixed RemoveConsoleCtrlHandler.
- CreateProcess should send the console control handler to csrss.

svn path=/trunk/; revision=5640
This commit is contained in:
Hartmut Birr 2003-08-18 10:47:04 +00:00
parent a11c2e5606
commit 74b741f04a
4 changed files with 22 additions and 10 deletions

View file

@ -27,6 +27,7 @@ typedef struct
{
ULONG NewProcessId;
ULONG Flags;
PCONTROLDISPATCHER CtrlDispatcher;
} CSRSS_CREATE_PROCESS_REQUEST, *PCSRSS_CREATE_PROCESS_REQUEST;
typedef struct

View file

@ -1,4 +1,4 @@
/* $Id: console.c,v 1.67 2003/08/18 07:32:00 jimtabor Exp $
/* $Id: console.c,v 1.68 2003/08/18 10:47:04 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -30,10 +30,8 @@ extern BOOL WINAPI IsDebuggerPresent(VOID);
static BOOL IgnoreCtrlEvents = FALSE;
static PHANDLER_ROUTINE StaticCtrlHandlers[] =
{ (PHANDLER_ROUTINE) &DefaultConsoleCtrlHandler };
static PHANDLER_ROUTINE* CtrlHandlers = StaticCtrlHandlers;
static ULONG NrCtrlHandlers = _NOACHS(StaticCtrlHandlers);
static PHANDLER_ROUTINE* CtrlHandlers = NULL;
static ULONG NrCtrlHandlers = 0;
static ULONG CtrlHandlersArraySize = 0;
/* Default Console Control Handler *******************************************/
@ -46,10 +44,12 @@ BOOL WINAPI DefaultConsoleCtrlHandler(DWORD Event)
{
case CTRL_C_EVENT:
DPRINT("Ctrl-C Event\n");
ExitProcess(0);
break;
case CTRL_BREAK_EVENT:
DPRINT("Ctrl-Break Event\n");
ExitProcess(0);
break;
case CTRL_SHUTDOWN_EVENT:
@ -2645,6 +2645,7 @@ AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine)
NrCtrlHandlers * sizeof(PHANDLER_ROUTINE));
if (CtrlHandlers == NULL)
{
NrCtrlHandlers = 0;
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return(FALSE);
}
@ -2670,8 +2671,9 @@ RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine)
{
if ( ((void*)(CtrlHandlers[i])) == (void*)HandlerRoutine)
{
CtrlHandlers[i] = CtrlHandlers[NrCtrlHandlers - 1];
NrCtrlHandlers--;
memmove(CtrlHandlers + i, CtrlHandlers + i + 1,
(NrCtrlHandlers - i) * sizeof(PHANDLER_ROUTINE));
CtrlHandlers =
RtlReAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,

View file

@ -1,4 +1,4 @@
/* $Id: dllmain.c,v 1.28 2003/08/16 06:19:15 jimtabor Exp $
/* $Id: dllmain.c,v 1.29 2003/08/18 10:47:04 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -35,6 +35,8 @@ DllMain(HANDLE hInst,
CRITICAL_SECTION DllLock;
CRITICAL_SECTION ConsoleLock;
extern BOOL WINAPI DefaultConsoleCtrlHandler(DWORD Event);
/* FUNCTIONS *****************************************************************/
static NTSTATUS
@ -129,7 +131,10 @@ DllMain(HANDLE hDll,
/* Initialize the DLL critical section */
RtlInitializeCriticalSection(&DllLock);
/* Initialize console ctrl handler */
RtlInitializeCriticalSection(&ConsoleLock);
SetConsoleCtrlHandler(DefaultConsoleCtrlHandler, TRUE);
/* Insert more dll attach stuff here! */

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.68 2003/07/10 18:50:51 chorns Exp $
/* $Id: create.c,v 1.69 2003/08/18 10:47:04 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -18,6 +18,9 @@
/* FUNCTIONS ****************************************************************/
extern __declspec(noreturn)
VOID CALLBACK ConsoleControlDispatcher(DWORD CodeAndFlag);
__declspec(dllimport)
PRTL_BASE_PROCESS_START_ROUTINE RtlBaseProcessStartRoutine;
@ -194,7 +197,7 @@ BOOL STDCALL CreateProcessA
ANSI_STRING strEnvVar;
/* scan the environment to calculate its Unicode size */
for(pcScan = lpEnvironment; *pcScan; pcScan += strEnvVar.MaximumLength)
for(pcScan = lpEnvironment; *pcScan; pcScan += strEnvVar.Length + sizeof(char))
{
/* add the size of the current variable */
RtlInitAnsiString(&strEnvVar, pcScan);
@ -226,7 +229,7 @@ BOOL STDCALL CreateProcessA
wstrEnvVar.MaximumLength = nEnvLen;
/* scan the environment to convert it */
for(pcScan = lpEnvironment; *pcScan; pcScan += strEnvVar.MaximumLength)
for(pcScan = lpEnvironment; *pcScan; pcScan += strEnvVar.Length + sizeof(char))
{
/* convert the current variable */
RtlInitAnsiString(&strEnvVar, pcScan);
@ -1041,6 +1044,7 @@ CreateProcessW
dwCreationFlags |= DETACHED_PROCESS;
}
CsrRequest.Data.CreateProcessRequest.Flags = dwCreationFlags;
CsrRequest.Data.CreateProcessRequest.CtrlDispatcher = ConsoleControlDispatcher;
Status = CsrClientCallServer(&CsrRequest,
&CsrReply,
sizeof(CSRSS_API_REQUEST),