[ros-diffs] [gschneider] 47502: [CMD] Protect certain actions with a critical section, patch by Katayama Hirofumi See issue #5406 for more details.

gschneider at svn.reactos.org gschneider at svn.reactos.org
Mon May 31 20:38:49 CEST 2010


Author: gschneider
Date: Mon May 31 20:38:48 2010
New Revision: 47502

URL: http://svn.reactos.org/svn/reactos?rev=47502&view=rev
Log:
[CMD] Protect certain actions with a critical section, patch by Katayama Hirofumi
See issue #5406 for more details.

Modified:
    trunk/reactos/base/shell/cmd/cmd.c

Modified: trunk/reactos/base/shell/cmd/cmd.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.c?rev=47502&r1=47501&r2=47502&view=diff
==============================================================================
--- trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] Mon May 31 20:38:48 2010
@@ -156,7 +156,7 @@
 BOOL bCtrlBreak = FALSE;  /* Ctrl-Break or Ctrl-C hit */
 BOOL bIgnoreEcho = FALSE; /* Set this to TRUE to prevent a newline, when executing a command */
 INT  nErrorLevel = 0;     /* Errorlevel of last launched external program */
-BOOL bChildProcessRunning = FALSE;
+CRITICAL_SECTION ChildProcessRunningLock;
 BOOL bUnicodeOutput = FALSE;
 BOOL bDisableBatchEcho = FALSE;
 BOOL bDelayedExpansion = FALSE;
@@ -436,14 +436,12 @@
 		{
 			if (IsConsoleProcess(prci.hProcess))
 			{
-				/* FIXME: Protect this with critical section */
-				bChildProcessRunning = TRUE;
+				EnterCriticalSection(&ChildProcessRunningLock);
 				dwChildProcessId = prci.dwProcessId;
 
 				WaitForSingleObject (prci.hProcess, INFINITE);
 
-				/* FIXME: Protect this with critical section */
-				bChildProcessRunning = FALSE;
+				LeaveCriticalSection(&ChildProcessRunningLock);
 
 				GetExitCodeProcess (prci.hProcess, &dwExitCode);
 				nErrorLevel = (INT)dwExitCode;
@@ -665,9 +663,9 @@
 	SetStdHandle(STD_INPUT_HANDLE, hOldConIn);
 
 	/* Wait for all processes to complete */
-	bChildProcessRunning = TRUE;
+	EnterCriticalSection(&ChildProcessRunningLock);
 	WaitForMultipleObjects(nProcesses, hProcess, TRUE, INFINITE);
-	bChildProcessRunning = FALSE;
+	LeaveCriticalSection(&ChildProcessRunningLock);
 
 	/* Use the exit code of the last process in the pipeline */
 	GetExitCodeProcess(hProcess[nProcesses - 1], &dwExitCode);
@@ -1439,13 +1437,16 @@
 		}
 	}
 
-	if (bChildProcessRunning == TRUE)
+	if (!TryEnterCriticalSection(&ChildProcessRunningLock))
 	{
 		SelfGenerated = TRUE;
 		GenerateConsoleCtrlEvent (dwCtrlType, 0);
 		return TRUE;
 	}
-
+	else
+	{
+		LeaveCriticalSection(&ChildProcessRunningLock);
+	}
 
     rec.EventType = KEY_EVENT;
     rec.Event.KeyEvent.bKeyDown = TRUE;
@@ -1797,6 +1798,7 @@
 	RemoveBreakHandler ();
 	SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE ),
 			ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT );
+	DeleteCriticalSection(&ChildProcessRunningLock);
 }
 
 /*
@@ -1808,6 +1810,7 @@
 	TCHAR startPath[MAX_PATH];
 	CONSOLE_SCREEN_BUFFER_INFO Info;
 
+	InitializeCriticalSection(&ChildProcessRunningLock);
 	lpOriginalEnvironment = DuplicateEnvironment();
 
 	GetCurrentDirectory(MAX_PATH,startPath);




More information about the Ros-diffs mailing list