mirror of
https://github.com/reactos/reactos.git
synced 2025-01-04 21:38:43 +00:00
[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. svn path=/trunk/; revision=50926
This commit is contained in:
parent
061ec721f9
commit
a328e318a1
3 changed files with 39 additions and 0 deletions
|
@ -30,6 +30,8 @@ LIST_ENTRY ServiceListHead;
|
|||
static RTL_RESOURCE DatabaseLock;
|
||||
static DWORD dwResumeCount = 1;
|
||||
|
||||
static CRITICAL_SECTION NamedPipeCriticalSection;
|
||||
static CRITICAL_SECTION StartServiceCriticalSection;
|
||||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
|
@ -704,6 +706,8 @@ ScmControlService(PSERVICE Service,
|
|||
ControlPacket->hServiceStatus = (SERVICE_STATUS_HANDLE)Service;
|
||||
wcscpy(&ControlPacket->szArguments[0], Service->lpServiceName);
|
||||
|
||||
EnterCriticalSection(&NamedPipeCriticalSection);
|
||||
|
||||
/* Send the control packet */
|
||||
WriteFile(Service->ControlPipeHandle,
|
||||
ControlPacket,
|
||||
|
@ -718,6 +722,8 @@ ScmControlService(PSERVICE Service,
|
|||
&dwReadCount,
|
||||
NULL);
|
||||
|
||||
LeaveCriticalSection(&NamedPipeCriticalSection);
|
||||
|
||||
/* Release the contol packet */
|
||||
HeapFree(GetProcessHeap(),
|
||||
0,
|
||||
|
@ -795,6 +801,8 @@ ScmSendStartCommand(PSERVICE Service,
|
|||
/* Terminate the argument list */
|
||||
*Ptr = 0;
|
||||
|
||||
EnterCriticalSection(&NamedPipeCriticalSection);
|
||||
|
||||
/* Send the start command */
|
||||
WriteFile(Service->ControlPipeHandle,
|
||||
ControlPacket,
|
||||
|
@ -809,6 +817,8 @@ ScmSendStartCommand(PSERVICE Service,
|
|||
&dwReadCount,
|
||||
NULL);
|
||||
|
||||
LeaveCriticalSection(&NamedPipeCriticalSection);
|
||||
|
||||
/* Release the contol packet */
|
||||
HeapFree(GetProcessHeap(),
|
||||
0,
|
||||
|
@ -912,6 +922,8 @@ ScmStartUserModeService(PSERVICE Service,
|
|||
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 @@ ScmStartUserModeService(PSERVICE Service,
|
|||
if (Service->ControlPipeHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DPRINT1("Failed to create control pipe!\n");
|
||||
LeaveCriticalSection(&StartServiceCriticalSection);
|
||||
return GetLastError();
|
||||
}
|
||||
|
||||
|
@ -957,6 +970,7 @@ ScmStartUserModeService(PSERVICE Service,
|
|||
Service->ControlPipeHandle = INVALID_HANDLE_VALUE;
|
||||
|
||||
DPRINT1("Starting '%S' failed!\n", Service->lpServiceName);
|
||||
LeaveCriticalSection(&StartServiceCriticalSection);
|
||||
return dwError;
|
||||
}
|
||||
|
||||
|
@ -1016,6 +1030,8 @@ ScmStartUserModeService(PSERVICE Service,
|
|||
CloseHandle(ProcessInformation.hThread);
|
||||
CloseHandle(ProcessInformation.hProcess);
|
||||
|
||||
LeaveCriticalSection(&StartServiceCriticalSection);
|
||||
|
||||
return dwError;
|
||||
}
|
||||
|
||||
|
@ -1257,4 +1273,20 @@ ScmUnlockDatabase(VOID)
|
|||
RtlReleaseResource(&DatabaseLock);
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
ScmInitNamedPipeCriticalSection(VOID)
|
||||
{
|
||||
InitializeCriticalSection(&NamedPipeCriticalSection);
|
||||
InitializeCriticalSection(&StartServiceCriticalSection);
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
ScmDeleteNamedPipeCriticalSection(VOID)
|
||||
{
|
||||
DeleteCriticalSection(&StartServiceCriticalSection);
|
||||
DeleteCriticalSection(&NamedPipeCriticalSection);
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -385,6 +385,8 @@ wWinMain(HINSTANCE hInstance,
|
|||
/* Acquire privileges to load drivers */
|
||||
AcquireLoadDriverPrivilege();
|
||||
|
||||
ScmInitNamedPipeCriticalSection();
|
||||
|
||||
/* Start auto-start services */
|
||||
ScmAutoStartServices();
|
||||
|
||||
|
@ -404,6 +406,8 @@ wWinMain(HINSTANCE hInstance,
|
|||
}
|
||||
#endif
|
||||
|
||||
ScmDeleteNamedPipeCriticalSection();
|
||||
|
||||
CloseHandle(hScmStartEvent);
|
||||
|
||||
DPRINT("SERVICES: Finished.\n");
|
||||
|
|
|
@ -123,6 +123,9 @@ BOOL ScmLockDatabaseExclusive(VOID);
|
|||
BOOL ScmLockDatabaseShared(VOID);
|
||||
VOID ScmUnlockDatabase(VOID);
|
||||
|
||||
VOID ScmInitNamedPipeCriticalSection(VOID);
|
||||
VOID ScmDeleteNamedPipeCriticalSection(VOID);
|
||||
|
||||
|
||||
/* driver.c */
|
||||
|
||||
|
|
Loading…
Reference in a new issue