mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 07:56:59 +00:00
[ADVAPI32-SERVICES]
- Apply changes from http://code.reactos.org/cru/CR-30 - If an event object already exists, CreateEvent returns a valid handle to it. So that, if the returned handle is NULL, then automatically we are sure that it doesn't exist. Therefore remove unneeded checks. svn path=/trunk/; revision=58856
This commit is contained in:
parent
6f55066617
commit
0950be976a
4 changed files with 22 additions and 93 deletions
|
@ -38,7 +38,7 @@ LIST_ENTRY ServiceListHead;
|
||||||
static RTL_RESOURCE DatabaseLock;
|
static RTL_RESOURCE DatabaseLock;
|
||||||
static DWORD ResumeCount = 1;
|
static DWORD ResumeCount = 1;
|
||||||
|
|
||||||
/* The critical section synchronizes service controls commands */
|
/* The critical section synchronizes service control requests */
|
||||||
static CRITICAL_SECTION ControlServiceCriticalSection;
|
static CRITICAL_SECTION ControlServiceCriticalSection;
|
||||||
static DWORD PipeTimeout = 30000; /* 30 Seconds */
|
static DWORD PipeTimeout = 30000; /* 30 Seconds */
|
||||||
|
|
||||||
|
@ -777,6 +777,7 @@ ScmCheckDriver(PSERVICE Service)
|
||||||
}
|
}
|
||||||
else // if (Service->Status.dwServiceType == SERVICE_FILE_SYSTEM_DRIVER)
|
else // if (Service->Status.dwServiceType == SERVICE_FILE_SYSTEM_DRIVER)
|
||||||
{
|
{
|
||||||
|
ASSERT(Service->Status.dwServiceType == SERVICE_FILE_SYSTEM_DRIVER);
|
||||||
RtlInitUnicodeString(&DirName, L"\\FileSystem");
|
RtlInitUnicodeString(&DirName, L"\\FileSystem");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -897,6 +898,7 @@ ScmControlService(PSERVICE Service,
|
||||||
|
|
||||||
DPRINT("ScmControlService() called\n");
|
DPRINT("ScmControlService() called\n");
|
||||||
|
|
||||||
|
/* Acquire the service control critical section, to synchronize requests */
|
||||||
EnterCriticalSection(&ControlServiceCriticalSection);
|
EnterCriticalSection(&ControlServiceCriticalSection);
|
||||||
|
|
||||||
/* Calculate the total length of the start command line */
|
/* Calculate the total length of the start command line */
|
||||||
|
@ -1715,8 +1717,6 @@ VOID
|
||||||
ScmAutoStartServices(VOID)
|
ScmAutoStartServices(VOID)
|
||||||
{
|
{
|
||||||
DWORD dwError = ERROR_SUCCESS;
|
DWORD dwError = ERROR_SUCCESS;
|
||||||
SC_RPC_LOCK Lock = NULL;
|
|
||||||
|
|
||||||
PLIST_ENTRY GroupEntry;
|
PLIST_ENTRY GroupEntry;
|
||||||
PLIST_ENTRY ServiceEntry;
|
PLIST_ENTRY ServiceEntry;
|
||||||
PSERVICE_GROUP CurrentGroup;
|
PSERVICE_GROUP CurrentGroup;
|
||||||
|
@ -1725,27 +1725,15 @@ ScmAutoStartServices(VOID)
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
ULONG i;
|
ULONG i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function MUST be called ONLY at initialization time.
|
||||||
|
* Therefore, no need to acquire the user service start lock.
|
||||||
|
*/
|
||||||
|
ASSERT(ScmInitialize);
|
||||||
|
|
||||||
/* Acquire the service control critical section, to synchronize starts */
|
/* Acquire the service control critical section, to synchronize starts */
|
||||||
EnterCriticalSection(&ControlServiceCriticalSection);
|
EnterCriticalSection(&ControlServiceCriticalSection);
|
||||||
|
|
||||||
/*
|
|
||||||
* Acquire the user service start lock while the service is starting, if
|
|
||||||
* needed (i.e. if we are not starting it during the initialization phase).
|
|
||||||
* If we don't success, bail out.
|
|
||||||
*/
|
|
||||||
if (!ScmInitialize)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Actually this code is never executed since we are called
|
|
||||||
* at initialization time, so that ScmInitialize == TRUE.
|
|
||||||
* But keep the code here if someday we are called later on
|
|
||||||
* for whatever reason...
|
|
||||||
*/
|
|
||||||
dwError = ScmAcquireServiceStartLock(TRUE, &Lock);
|
|
||||||
if (dwError != ERROR_SUCCESS) goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Clear 'ServiceVisited' flag (or set if not to start in Safe Mode) */
|
/* Clear 'ServiceVisited' flag (or set if not to start in Safe Mode) */
|
||||||
ServiceEntry = ServiceListHead.Flink;
|
ServiceEntry = ServiceListHead.Flink;
|
||||||
while (ServiceEntry != &ServiceListHead)
|
while (ServiceEntry != &ServiceListHead)
|
||||||
|
@ -1906,11 +1894,7 @@ ScmAutoStartServices(VOID)
|
||||||
ServiceEntry = ServiceEntry->Flink;
|
ServiceEntry = ServiceEntry->Flink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Release the critical section */
|
||||||
/* Release the service start lock, if needed, and the critical section */
|
|
||||||
if (Lock) ScmReleaseServiceStartLock(&Lock);
|
|
||||||
|
|
||||||
done:
|
|
||||||
LeaveCriticalSection(&ControlServiceCriticalSection);
|
LeaveCriticalSection(&ControlServiceCriticalSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,6 +145,7 @@ ScmGetDriverStatus(PSERVICE lpService,
|
||||||
}
|
}
|
||||||
else // if (lpService->Status.dwServiceType == SERVICE_FILE_SYSTEM_DRIVER)
|
else // if (lpService->Status.dwServiceType == SERVICE_FILE_SYSTEM_DRIVER)
|
||||||
{
|
{
|
||||||
|
ASSERT(lpService->Status.dwServiceType == SERVICE_FILE_SYSTEM_DRIVER);
|
||||||
RtlInitUnicodeString(&DirName, L"\\FileSystem");
|
RtlInitUnicodeString(&DirName, L"\\FileSystem");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,50 +82,11 @@ ScmLogError(DWORD dwEventId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOL
|
|
||||||
ScmCreateControlEvent(PHANDLE Event,
|
|
||||||
LPCWSTR Name,
|
|
||||||
DWORD dwDesiredAccess)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* This function creates a generic non-inheritable event
|
|
||||||
* and return a handle to the caller. The caller must
|
|
||||||
* close this handle afterwards.
|
|
||||||
*/
|
|
||||||
|
|
||||||
HANDLE hEvent;
|
|
||||||
|
|
||||||
hEvent = CreateEventW(NULL, TRUE, FALSE, Name);
|
|
||||||
if (hEvent == NULL)
|
|
||||||
{
|
|
||||||
if (GetLastError() == ERROR_ALREADY_EXISTS)
|
|
||||||
{
|
|
||||||
hEvent = OpenEventW(dwDesiredAccess, FALSE, Name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hEvent)
|
|
||||||
{
|
|
||||||
DPRINT("SERVICES: Created event %S with handle %x\n", Name, hEvent);
|
|
||||||
*Event = hEvent;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DPRINT1("SERVICES: Failed to create event %S (Error %lu)\n", Name, GetLastError());
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
ScmWaitForLsa(VOID)
|
ScmWaitForLsa(VOID)
|
||||||
{
|
{
|
||||||
HANDLE hEvent;
|
HANDLE hEvent = CreateEventW(NULL, TRUE, FALSE, LSA_RPC_SERVER_ACTIVE);
|
||||||
|
if (hEvent == NULL)
|
||||||
if (!ScmCreateControlEvent(&hEvent,
|
|
||||||
LSA_RPC_SERVER_ACTIVE,
|
|
||||||
SYNCHRONIZE))
|
|
||||||
{
|
{
|
||||||
DPRINT1("Failed to create the notification event (Error %lu)\n", GetLastError());
|
DPRINT1("Failed to create the notification event (Error %lu)\n", GetLastError());
|
||||||
}
|
}
|
||||||
|
@ -134,7 +95,6 @@ ScmWaitForLsa(VOID)
|
||||||
DPRINT("Wait for the LSA server!\n");
|
DPRINT("Wait for the LSA server!\n");
|
||||||
WaitForSingleObject(hEvent, INFINITE);
|
WaitForSingleObject(hEvent, INFINITE);
|
||||||
DPRINT("LSA server running!\n");
|
DPRINT("LSA server running!\n");
|
||||||
|
|
||||||
CloseHandle(hEvent);
|
CloseHandle(hEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,9 +317,8 @@ wWinMain(HINSTANCE hInstance,
|
||||||
ScmInitialize = TRUE;
|
ScmInitialize = TRUE;
|
||||||
|
|
||||||
/* Create the start event */
|
/* Create the start event */
|
||||||
if (!ScmCreateControlEvent(&hScmStartEvent,
|
hScmStartEvent = CreateEventW(NULL, TRUE, FALSE, SCM_START_EVENT);
|
||||||
SCM_START_EVENT,
|
if (hScmStartEvent == NULL)
|
||||||
EVENT_ALL_ACCESS))
|
|
||||||
{
|
{
|
||||||
DPRINT1("SERVICES: Failed to create the start event\n");
|
DPRINT1("SERVICES: Failed to create the start event\n");
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -367,9 +326,8 @@ wWinMain(HINSTANCE hInstance,
|
||||||
DPRINT("SERVICES: Created start event with handle %p.\n", hScmStartEvent);
|
DPRINT("SERVICES: Created start event with handle %p.\n", hScmStartEvent);
|
||||||
|
|
||||||
/* Create the auto-start complete event */
|
/* Create the auto-start complete event */
|
||||||
if (!ScmCreateControlEvent(&hScmAutoStartCompleteEvent,
|
hScmAutoStartCompleteEvent = CreateEventW(NULL, TRUE, FALSE, SCM_AUTOSTARTCOMPLETE_EVENT);
|
||||||
SCM_AUTOSTARTCOMPLETE_EVENT,
|
if (hScmAutoStartCompleteEvent = NULL)
|
||||||
EVENT_ALL_ACCESS))
|
|
||||||
{
|
{
|
||||||
DPRINT1("SERVICES: Failed to create the auto-start complete event\n");
|
DPRINT1("SERVICES: Failed to create the auto-start complete event\n");
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -380,7 +338,7 @@ wWinMain(HINSTANCE hInstance,
|
||||||
hScmShutdownEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
|
hScmShutdownEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
|
||||||
if (hScmShutdownEvent == NULL)
|
if (hScmShutdownEvent == NULL)
|
||||||
{
|
{
|
||||||
DPRINT1("SERVICES: Failed to create shutdown event\n");
|
DPRINT1("SERVICES: Failed to create the shutdown event\n");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1673,28 +1673,14 @@ WaitForSCManager(VOID)
|
||||||
TRACE("WaitForSCManager() called\n");
|
TRACE("WaitForSCManager() called\n");
|
||||||
|
|
||||||
/* Try to open the existing event */
|
/* Try to open the existing event */
|
||||||
hEvent = OpenEventW(SYNCHRONIZE,
|
hEvent = OpenEventW(SYNCHRONIZE, FALSE, SCM_START_EVENT);
|
||||||
FALSE,
|
|
||||||
SCM_START_EVENT);
|
|
||||||
if (hEvent == NULL)
|
if (hEvent == NULL)
|
||||||
{
|
{
|
||||||
if (GetLastError() != ERROR_FILE_NOT_FOUND)
|
if (GetLastError() != ERROR_FILE_NOT_FOUND) return;
|
||||||
return;
|
|
||||||
|
|
||||||
/* Try to create a new event */
|
/* Try to create a new event */
|
||||||
hEvent = CreateEventW(NULL,
|
hEvent = CreateEventW(NULL, TRUE, FALSE, SCM_START_EVENT);
|
||||||
TRUE,
|
if (hEvent == NULL) return;
|
||||||
FALSE,
|
|
||||||
SCM_START_EVENT);
|
|
||||||
if (hEvent == NULL)
|
|
||||||
{
|
|
||||||
/* Try to open the existing event again */
|
|
||||||
hEvent = OpenEventW(SYNCHRONIZE,
|
|
||||||
FALSE,
|
|
||||||
SCM_START_EVENT);
|
|
||||||
if (hEvent == NULL)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for 3 minutes */
|
/* Wait for 3 minutes */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue