Author: hbelusca
Date: Thu Apr 25 23:13:58 2013
New Revision: 58856
URL:
http://svn.reactos.org/svn/reactos?rev=58856&view=rev
Log:
[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.
Modified:
trunk/reactos/base/system/services/database.c
trunk/reactos/base/system/services/driver.c
trunk/reactos/base/system/services/services.c
trunk/reactos/dll/win32/advapi32/service/scm.c
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] Thu Apr 25 23:13:58 2013
@@ -38,7 +38,7 @@
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 @@
}
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 @@
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 @@
ScmAutoStartServices(VOID)
{
DWORD dwError = ERROR_SUCCESS;
- SC_RPC_LOCK Lock = NULL;
-
PLIST_ENTRY GroupEntry;
PLIST_ENTRY ServiceEntry;
PSERVICE_GROUP CurrentGroup;
@@ -1725,26 +1725,14 @@
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;
@@ -1906,11 +1894,7 @@
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);
}
Modified: trunk/reactos/base/system/services/driver.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/drive…
==============================================================================
--- trunk/reactos/base/system/services/driver.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/services/driver.c [iso-8859-1] Thu Apr 25 23:13:58 2013
@@ -145,6 +145,7 @@
}
else // if (lpService->Status.dwServiceType == SERVICE_FILE_SYSTEM_DRIVER)
{
+ ASSERT(lpService->Status.dwServiceType == SERVICE_FILE_SYSTEM_DRIVER);
RtlInitUnicodeString(&DirName, L"\\FileSystem");
}
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] Thu Apr 25 23:13:58 2013
@@ -82,50 +82,11 @@
}
-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 @@
DPRINT("Wait for the LSA server!\n");
WaitForSingleObject(hEvent, INFINITE);
DPRINT("LSA server running!\n");
-
CloseHandle(hEvent);
}
@@ -357,9 +317,8 @@
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 @@
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 @@
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;
}
Modified: trunk/reactos/dll/win32/advapi32/service/scm.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/service…
==============================================================================
--- trunk/reactos/dll/win32/advapi32/service/scm.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/advapi32/service/scm.c [iso-8859-1] Thu Apr 25 23:13:58 2013
@@ -1673,28 +1673,14 @@
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 */