Author: ekohl
Date: Sun Feb 27 19:25:14 2011
New Revision: 50926
URL:
http://svn.reactos.org/svn/reactos?rev=50926&view=rev
Log:
[SERVICES]
Protect the service start and sending of control packages by critical sections. This way,
services will be started one by one and control packages will also be sent one by one.
Please test if this fixes bug #5924.
Modified:
trunk/reactos/base/system/services/database.c
trunk/reactos/base/system/services/services.c
trunk/reactos/base/system/services/services.h
Modified: trunk/reactos/base/system/services/database.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/datab…
==============================================================================
--- trunk/reactos/base/system/services/database.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/services/database.c [iso-8859-1] Sun Feb 27 19:25:14 2011
@@ -30,6 +30,8 @@
static RTL_RESOURCE DatabaseLock;
static DWORD dwResumeCount = 1;
+static CRITICAL_SECTION NamedPipeCriticalSection;
+static CRITICAL_SECTION StartServiceCriticalSection;
/* FUNCTIONS *****************************************************************/
@@ -704,6 +706,8 @@
ControlPacket->hServiceStatus = (SERVICE_STATUS_HANDLE)Service;
wcscpy(&ControlPacket->szArguments[0], Service->lpServiceName);
+ EnterCriticalSection(&NamedPipeCriticalSection);
+
/* Send the control packet */
WriteFile(Service->ControlPipeHandle,
ControlPacket,
@@ -717,6 +721,8 @@
sizeof(SCM_REPLY_PACKET),
&dwReadCount,
NULL);
+
+ LeaveCriticalSection(&NamedPipeCriticalSection);
/* Release the contol packet */
HeapFree(GetProcessHeap(),
@@ -795,6 +801,8 @@
/* Terminate the argument list */
*Ptr = 0;
+ EnterCriticalSection(&NamedPipeCriticalSection);
+
/* Send the start command */
WriteFile(Service->ControlPipeHandle,
ControlPacket,
@@ -808,6 +816,8 @@
sizeof(SCM_REPLY_PACKET),
&dwReadCount,
NULL);
+
+ LeaveCriticalSection(&NamedPipeCriticalSection);
/* Release the contol packet */
HeapFree(GetProcessHeap(),
@@ -912,6 +922,8 @@
return Status;
}
+ EnterCriticalSection(&StartServiceCriticalSection);
+
/* Create '\\.\pipe\net\NtControlPipeXXX' instance */
swprintf(NtControlPipeName, L"\\\\.\\pipe\\net\\NtControlPipe%u",
ServiceCurrent);
Service->ControlPipeHandle = CreateNamedPipeW(NtControlPipeName,
@@ -926,6 +938,7 @@
if (Service->ControlPipeHandle == INVALID_HANDLE_VALUE)
{
DPRINT1("Failed to create control pipe!\n");
+ LeaveCriticalSection(&StartServiceCriticalSection);
return GetLastError();
}
@@ -957,6 +970,7 @@
Service->ControlPipeHandle = INVALID_HANDLE_VALUE;
DPRINT1("Starting '%S' failed!\n", Service->lpServiceName);
+ LeaveCriticalSection(&StartServiceCriticalSection);
return dwError;
}
@@ -1015,6 +1029,8 @@
/* Close process and thread handle */
CloseHandle(ProcessInformation.hThread);
CloseHandle(ProcessInformation.hProcess);
+
+ LeaveCriticalSection(&StartServiceCriticalSection);
return dwError;
}
@@ -1257,4 +1273,20 @@
RtlReleaseResource(&DatabaseLock);
}
+
+VOID
+ScmInitNamedPipeCriticalSection(VOID)
+{
+ InitializeCriticalSection(&NamedPipeCriticalSection);
+ InitializeCriticalSection(&StartServiceCriticalSection);
+}
+
+
+VOID
+ScmDeleteNamedPipeCriticalSection(VOID)
+{
+ DeleteCriticalSection(&StartServiceCriticalSection);
+ DeleteCriticalSection(&NamedPipeCriticalSection);
+}
+
/* EOF */
Modified: trunk/reactos/base/system/services/services.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/servi…
==============================================================================
--- trunk/reactos/base/system/services/services.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/services/services.c [iso-8859-1] Sun Feb 27 19:25:14 2011
@@ -385,6 +385,8 @@
/* Acquire privileges to load drivers */
AcquireLoadDriverPrivilege();
+ ScmInitNamedPipeCriticalSection();
+
/* Start auto-start services */
ScmAutoStartServices();
@@ -404,6 +406,8 @@
}
#endif
+ ScmDeleteNamedPipeCriticalSection();
+
CloseHandle(hScmStartEvent);
DPRINT("SERVICES: Finished.\n");
Modified: trunk/reactos/base/system/services/services.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/servi…
==============================================================================
--- trunk/reactos/base/system/services/services.h [iso-8859-1] (original)
+++ trunk/reactos/base/system/services/services.h [iso-8859-1] Sun Feb 27 19:25:14 2011
@@ -123,6 +123,9 @@
BOOL ScmLockDatabaseShared(VOID);
VOID ScmUnlockDatabase(VOID);
+VOID ScmInitNamedPipeCriticalSection(VOID);
+VOID ScmDeleteNamedPipeCriticalSection(VOID);
+
/* driver.c */