Author: hbelusca
Date: Sun Nov 23 14:26:37 2014
New Revision: 65457
URL:
http://svn.reactos.org/svn/reactos?rev=65457&view=rev
Log:
[CONSRV]: Reduce code duplication and remove unused InputWaitHandle member.
Modified:
trunk/reactos/win32ss/user/winsrv/consrv/console.c
trunk/reactos/win32ss/user/winsrv/consrv/consrv.h
trunk/reactos/win32ss/user/winsrv/consrv/handle.c
trunk/reactos/win32ss/user/winsrv/consrv/init.c
trunk/reactos/win32ss/user/winsrv/consrv/procinit.h
Modified: trunk/reactos/win32ss/user/winsrv/consrv/console.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv…
==============================================================================
--- trunk/reactos/win32ss/user/winsrv/consrv/console.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/winsrv/consrv/console.c [iso-8859-1] Sun Nov 23 14:26:37
2014
@@ -283,8 +283,6 @@
ASSERT(Console);
*Console = NULL;
- // RtlEnterCriticalSection(&ProcessData->HandleTableLock);
-
if (ConSrvValidateConsole(&GrabConsole,
ProcessData->ConsoleHandle,
CONSOLE_RUNNING,
@@ -295,7 +293,6 @@
Status = STATUS_SUCCESS;
}
- // RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
return Status;
}
@@ -948,14 +945,6 @@
return Status;
}
- /* Mark the process as having a console */
- ProcessData->ConsoleApp = TRUE;
- CsrProcess->Flags |= CsrProcessIsConsoleApp;
-
- /* Return the console handle and the input wait handle to the caller */
- AllocConsoleRequest->ConsoleStartInfo->ConsoleHandle =
ProcessData->ConsoleHandle;
- AllocConsoleRequest->ConsoleStartInfo->InputWaitHandle =
ProcessData->InputWaitHandle;
-
/* Set the Property-Dialog and Control-Dispatcher handlers */
ProcessData->PropRoutine = AllocConsoleRequest->PropRoutine;
ProcessData->CtrlRoutine = AllocConsoleRequest->CtrlRoutine;
@@ -1038,14 +1027,6 @@
goto Quit;
}
- /* Mark the process as having a console */
- TargetProcessData->ConsoleApp = TRUE;
- TargetProcess->Flags |= CsrProcessIsConsoleApp;
-
- /* Return the console handle and the input wait handle to the caller */
- AttachConsoleRequest->ConsoleStartInfo->ConsoleHandle =
TargetProcessData->ConsoleHandle;
- AttachConsoleRequest->ConsoleStartInfo->InputWaitHandle =
TargetProcessData->InputWaitHandle;
-
/* Set the Property-Dialog and Control-Dispatcher handlers */
TargetProcessData->PropRoutine = AttachConsoleRequest->PropRoutine;
TargetProcessData->CtrlRoutine = AttachConsoleRequest->CtrlRoutine;
@@ -1060,16 +1041,7 @@
CSR_API(SrvFreeConsole)
{
- PCSR_PROCESS CsrProcess = CsrGetClientThread()->Process;
- PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrProcess);
-
- ConSrvRemoveConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process));
-
- /* Mark the process as not having a console anymore */
- ProcessData->ConsoleApp = FALSE;
- CsrProcess->Flags &= ~CsrProcessIsConsoleApp;
-
- return STATUS_SUCCESS;
+ return
ConSrvRemoveConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process));
}
NTSTATUS NTAPI
Modified: trunk/reactos/win32ss/user/winsrv/consrv/consrv.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv…
==============================================================================
--- trunk/reactos/win32ss/user/winsrv/consrv/consrv.h [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/winsrv/consrv/consrv.h [iso-8859-1] Sun Nov 23 14:26:37
2014
@@ -53,9 +53,7 @@
PCSR_PROCESS Process; // Process owning this structure.
HANDLE ConsoleHandle;
- HANDLE InputWaitHandle;
-
- BOOLEAN ConsoleApp; // TRUE if it is a CUI app, FALSE otherwise.
+ BOOLEAN ConsoleApp; // TRUE if it is a CUI app, FALSE otherwise.
RTL_CRITICAL_SECTION HandleTableLock;
ULONG HandleTableSize;
Modified: trunk/reactos/win32ss/user/winsrv/consrv/handle.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv…
==============================================================================
--- trunk/reactos/win32ss/user/winsrv/consrv/handle.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/winsrv/consrv/handle.c [iso-8859-1] Sun Nov 23 14:26:37
2014
@@ -555,7 +555,7 @@
Status = NtDuplicateObject(NtCurrentProcess(),
Console->InputBuffer.ActiveEvent,
ProcessData->Process->ProcessHandle,
- &ProcessData->InputWaitHandle,
+
&ConsoleInitInfo->ConsoleStartInfo->InputWaitHandle,
EVENT_ALL_ACCESS, 0, 0);
if (!NT_SUCCESS(Status))
{
@@ -567,6 +567,13 @@
ProcessData->ConsoleHandle = NULL;
return Status;
}
+
+ /* Mark the process as having a console */
+ ProcessData->ConsoleApp = TRUE;
+ ProcessData->Process->Flags |= CsrProcessIsConsoleApp;
+
+ /* Return the console handle to the caller */
+ ConsoleInitInfo->ConsoleStartInfo->ConsoleHandle =
ProcessData->ConsoleHandle;
/* Insert the process into the processes list of the console */
InsertHeadList(&Console->ProcessList, &ProcessData->ConsoleLink);
@@ -664,7 +671,7 @@
Status = NtDuplicateObject(NtCurrentProcess(),
Console->InputBuffer.ActiveEvent,
ProcessData->Process->ProcessHandle,
- &ProcessData->InputWaitHandle,
+ &ConsoleStartInfo->InputWaitHandle,
EVENT_ALL_ACCESS, 0, 0);
if (!NT_SUCCESS(Status))
{
@@ -676,6 +683,13 @@
goto Quit;
}
+ /* Mark the process as having a console */
+ ProcessData->ConsoleApp = TRUE;
+ ProcessData->Process->Flags |= CsrProcessIsConsoleApp;
+
+ /* Return the console handle to the caller */
+ ConsoleStartInfo->ConsoleHandle = ProcessData->ConsoleHandle;
+
/* Insert the process into the processes list of the console */
InsertHeadList(&Console->ProcessList, &ProcessData->ConsoleLink);
@@ -693,74 +707,78 @@
return Status;
}
-VOID
+NTSTATUS
ConSrvRemoveConsole(PCONSOLE_PROCESS_DATA ProcessData)
{
PCONSOLE Console;
+ PCONSOLE_PROCESS_DATA ConsoleLeaderProcess;
DPRINT("ConSrvRemoveConsole\n");
- // RtlEnterCriticalSection(&ProcessData->HandleTableLock);
+ /* Mark the process as not having a console anymore */
+ ProcessData->ConsoleApp = FALSE;
+ ProcessData->Process->Flags &= ~CsrProcessIsConsoleApp;
/* Validate and lock the console */
- if (ConSrvValidateConsole(&Console,
- ProcessData->ConsoleHandle,
- CONSOLE_RUNNING, TRUE))
- {
- /* Retrieve the console leader process */
- PCONSOLE_PROCESS_DATA ConsoleLeaderProcess =
ConSrvGetConsoleLeaderProcess(Console);
-
- DPRINT("ConSrvRemoveConsole - Locking OK\n");
-
- /* Close all console handles and free the handles table */
- ConSrvFreeHandlesTable(ProcessData);
-
- /* Detach the process from the console */
- ProcessData->ConsoleHandle = NULL;
-
- /* Remove the process from the console's list of processes */
- RemoveEntryList(&ProcessData->ConsoleLink);
-
- /* Check whether the console should send a last close notification */
- if (Console->NotifyLastClose)
+ if (!ConSrvValidateConsole(&Console,
+ ProcessData->ConsoleHandle,
+ CONSOLE_RUNNING, TRUE))
+ {
+ // FIXME: Find another status code
+ return STATUS_UNSUCCESSFUL;
+ }
+
+ DPRINT("ConSrvRemoveConsole - Locking OK\n");
+
+ /* Retrieve the console leader process */
+ ConsoleLeaderProcess = ConSrvGetConsoleLeaderProcess(Console);
+
+ /* Close all console handles and free the handles table */
+ ConSrvFreeHandlesTable(ProcessData);
+
+ /* Detach the process from the console */
+ ProcessData->ConsoleHandle = NULL;
+
+ /* Remove the process from the console's list of processes */
+ RemoveEntryList(&ProcessData->ConsoleLink);
+
+ /* Check whether the console should send a last close notification */
+ if (Console->NotifyLastClose)
+ {
+ /* If we are removing the process which wants the last close notification... */
+ if (ProcessData == Console->NotifiedLastCloseProcess)
{
- /* If we are removing the process which wants the last close notification...
*/
- if (ProcessData == Console->NotifiedLastCloseProcess)
- {
- /* ... just reset the flag and the pointer... */
- Console->NotifyLastClose = FALSE;
- Console->NotifiedLastCloseProcess = NULL;
- }
+ /* ... just reset the flag and the pointer... */
+ Console->NotifyLastClose = FALSE;
+ Console->NotifiedLastCloseProcess = NULL;
+ }
+ /*
+ * ... otherwise, if we are removing the console leader process
+ * (that cannot be the process wanting the notification, because
+ * the previous case already dealt with it)...
+ */
+ else if (ProcessData == ConsoleLeaderProcess)
+ {
/*
- * ... otherwise, if we are removing the console leader process
- * (that cannot be the process wanting the notification, because
- * the previous case already dealt with it)...
+ * ... reset the flag first (so that we avoid multiple notifications)
+ * and then send the last close notification.
*/
- else if (ProcessData == ConsoleLeaderProcess)
- {
- /*
- * ... reset the flag first (so that we avoid multiple notifications)
- * and then send the last close notification.
- */
- Console->NotifyLastClose = FALSE;
- ConSrvConsoleCtrlEvent(CTRL_LAST_CLOSE_EVENT,
Console->NotifiedLastCloseProcess);
-
- /* Only now, reset the pointer */
- Console->NotifiedLastCloseProcess = NULL;
- }
+ Console->NotifyLastClose = FALSE;
+ ConSrvConsoleCtrlEvent(CTRL_LAST_CLOSE_EVENT,
Console->NotifiedLastCloseProcess);
+
+ /* Only now, reset the pointer */
+ Console->NotifiedLastCloseProcess = NULL;
}
-
- /* Update the internal info of the terminal */
- TermRefreshInternalInfo(Console);
-
- /* Release the console */
- DPRINT("ConSrvRemoveConsole - Decrement Console->ReferenceCount =
%lu\n", Console->ReferenceCount);
- ConSrvReleaseConsole(Console, TRUE);
- //CloseHandle(ProcessData->InputWaitHandle);
- //ProcessData->InputWaitHandle = NULL;
- }
-
- // RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
+ }
+
+ /* Update the internal info of the terminal */
+ TermRefreshInternalInfo(Console);
+
+ /* Release the console */
+ DPRINT("ConSrvRemoveConsole - Decrement Console->ReferenceCount =
%lu\n", Console->ReferenceCount);
+ ConSrvReleaseConsole(Console, TRUE);
+
+ return STATUS_SUCCESS;
}
Modified: trunk/reactos/win32ss/user/winsrv/consrv/init.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv…
==============================================================================
--- trunk/reactos/win32ss/user/winsrv/consrv/init.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/winsrv/consrv/init.c [iso-8859-1] Sun Nov 23 14:26:37 2014
@@ -353,7 +353,6 @@
/* Initialize the new (target) process */
RtlZeroMemory(TargetProcessData, sizeof(*TargetProcessData));
TargetProcessData->Process = TargetProcess;
- TargetProcessData->InputWaitHandle = NULL;
TargetProcessData->ConsoleHandle = NULL;
TargetProcessData->ConsoleApp = FALSE;
@@ -491,14 +490,6 @@
}
}
- /* Mark the process as having a console */
- ProcessData->ConsoleApp = TRUE;
- // ProcessData->Flags |= CsrProcessIsConsoleApp;
-
- /* Return the console handle and the input wait handle to the caller */
- ConnectInfo->ConsoleStartInfo.ConsoleHandle = ProcessData->ConsoleHandle;
- ConnectInfo->ConsoleStartInfo.InputWaitHandle = ProcessData->InputWaitHandle;
-
/* Set the Property-Dialog and Control-Dispatcher handlers */
ProcessData->PropRoutine = ConnectInfo->PropRoutine;
ProcessData->CtrlRoutine = ConnectInfo->CtrlRoutine;
@@ -521,10 +512,6 @@
{
DPRINT("ConSrvDisconnect - calling ConSrvRemoveConsole\n");
ConSrvRemoveConsole(ProcessData);
-
- /* Mark the process as not having a console anymore */
- ProcessData->ConsoleApp = FALSE;
- Process->Flags &= ~CsrProcessIsConsoleApp;
}
RtlDeleteCriticalSection(&ProcessData->HandleTableLock);
Modified: trunk/reactos/win32ss/user/winsrv/consrv/procinit.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv…
==============================================================================
--- trunk/reactos/win32ss/user/winsrv/consrv/procinit.h [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/winsrv/consrv/procinit.h [iso-8859-1] Sun Nov 23 14:26:37
2014
@@ -20,4 +20,4 @@
PHANDLE pOutputHandle,
PHANDLE pErrorHandle,
PCONSOLE_START_INFO ConsoleStartInfo);
-VOID ConSrvRemoveConsole(PCONSOLE_PROCESS_DATA ProcessData);
+NTSTATUS ConSrvRemoveConsole(PCONSOLE_PROCESS_DATA ProcessData);