[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:
Hermès Bélusca-Maïto 2013-04-25 23:13:58 +00:00
parent 6f55066617
commit 0950be976a
4 changed files with 22 additions and 93 deletions

View file

@ -38,7 +38,7 @@ LIST_ENTRY ServiceListHead;
static RTL_RESOURCE DatabaseLock;
static DWORD ResumeCount = 1;
/* The critical section synchronizes service controls commands */
/* The critical section synchronizes service control requests */
static CRITICAL_SECTION ControlServiceCriticalSection;
static DWORD PipeTimeout = 30000; /* 30 Seconds */
@ -777,6 +777,7 @@ ScmCheckDriver(PSERVICE Service)
}
else // if (Service->Status.dwServiceType == SERVICE_FILE_SYSTEM_DRIVER)
{
ASSERT(Service->Status.dwServiceType == SERVICE_FILE_SYSTEM_DRIVER);
RtlInitUnicodeString(&DirName, L"\\FileSystem");
}
@ -897,6 +898,7 @@ ScmControlService(PSERVICE Service,
DPRINT("ScmControlService() called\n");
/* Acquire the service control critical section, to synchronize requests */
EnterCriticalSection(&ControlServiceCriticalSection);
/* Calculate the total length of the start command line */
@ -1715,8 +1717,6 @@ VOID
ScmAutoStartServices(VOID)
{
DWORD dwError = ERROR_SUCCESS;
SC_RPC_LOCK Lock = NULL;
PLIST_ENTRY GroupEntry;
PLIST_ENTRY ServiceEntry;
PSERVICE_GROUP CurrentGroup;
@ -1725,27 +1725,15 @@ ScmAutoStartServices(VOID)
HKEY hKey;
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 */
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) */
ServiceEntry = ServiceListHead.Flink;
while (ServiceEntry != &ServiceListHead)
@ -1906,11 +1894,7 @@ ScmAutoStartServices(VOID)
ServiceEntry = ServiceEntry->Flink;
}
/* Release the service start lock, if needed, and the critical section */
if (Lock) ScmReleaseServiceStartLock(&Lock);
done:
/* Release the critical section */
LeaveCriticalSection(&ControlServiceCriticalSection);
}

View file

@ -145,6 +145,7 @@ ScmGetDriverStatus(PSERVICE lpService,
}
else // if (lpService->Status.dwServiceType == SERVICE_FILE_SYSTEM_DRIVER)
{
ASSERT(lpService->Status.dwServiceType == SERVICE_FILE_SYSTEM_DRIVER);
RtlInitUnicodeString(&DirName, L"\\FileSystem");
}

View file

@ -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
ScmWaitForLsa(VOID)
{
HANDLE hEvent;
if (!ScmCreateControlEvent(&hEvent,
LSA_RPC_SERVER_ACTIVE,
SYNCHRONIZE))
HANDLE hEvent = CreateEventW(NULL, TRUE, FALSE, LSA_RPC_SERVER_ACTIVE);
if (hEvent == NULL)
{
DPRINT1("Failed to create the notification event (Error %lu)\n", GetLastError());
}
@ -134,7 +95,6 @@ ScmWaitForLsa(VOID)
DPRINT("Wait for the LSA server!\n");
WaitForSingleObject(hEvent, INFINITE);
DPRINT("LSA server running!\n");
CloseHandle(hEvent);
}
@ -357,9 +317,8 @@ wWinMain(HINSTANCE hInstance,
ScmInitialize = TRUE;
/* Create the start event */
if (!ScmCreateControlEvent(&hScmStartEvent,
SCM_START_EVENT,
EVENT_ALL_ACCESS))
hScmStartEvent = CreateEventW(NULL, TRUE, FALSE, SCM_START_EVENT);
if (hScmStartEvent == NULL)
{
DPRINT1("SERVICES: Failed to create the start event\n");
goto done;
@ -367,9 +326,8 @@ wWinMain(HINSTANCE hInstance,
DPRINT("SERVICES: Created start event with handle %p.\n", hScmStartEvent);
/* Create the auto-start complete event */
if (!ScmCreateControlEvent(&hScmAutoStartCompleteEvent,
SCM_AUTOSTARTCOMPLETE_EVENT,
EVENT_ALL_ACCESS))
hScmAutoStartCompleteEvent = CreateEventW(NULL, TRUE, FALSE, SCM_AUTOSTARTCOMPLETE_EVENT);
if (hScmAutoStartCompleteEvent = NULL)
{
DPRINT1("SERVICES: Failed to create the auto-start complete event\n");
goto done;
@ -380,7 +338,7 @@ wWinMain(HINSTANCE hInstance,
hScmShutdownEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
if (hScmShutdownEvent == NULL)
{
DPRINT1("SERVICES: Failed to create shutdown event\n");
DPRINT1("SERVICES: Failed to create the shutdown event\n");
goto done;
}

View file

@ -1673,28 +1673,14 @@ WaitForSCManager(VOID)
TRACE("WaitForSCManager() called\n");
/* Try to open the existing event */
hEvent = OpenEventW(SYNCHRONIZE,
FALSE,
SCM_START_EVENT);
hEvent = OpenEventW(SYNCHRONIZE, FALSE, SCM_START_EVENT);
if (hEvent == NULL)
{
if (GetLastError() != ERROR_FILE_NOT_FOUND)
return;
if (GetLastError() != ERROR_FILE_NOT_FOUND) return;
/* Try to create a new event */
hEvent = CreateEventW(NULL,
TRUE,
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;
}
hEvent = CreateEventW(NULL, TRUE, FALSE, SCM_START_EVENT);
if (hEvent == NULL) return;
}
/* Wait for 3 minutes */