- Make the service manager wait for LSA.
authorEric Kohl <eric.kohl@reactos.org>
Sun, 14 Dec 2008 01:01:16 +0000 (01:01 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sun, 14 Dec 2008 01:01:16 +0000 (01:01 +0000)
- Winlogon must not wait for the service mananger, otherwise we will get another deadlock.

svn path=/trunk/; revision=38065

reactos/base/system/services/database.c
reactos/base/system/winlogon/winlogon.c

index 50ef276..a046057 100644 (file)
@@ -446,6 +446,46 @@ ScmDeleteMarkedServices(VOID)
 }
 
 
+VOID
+WaitForLSA(VOID)
+{
+    HANDLE hEvent;
+    DWORD dwError;
+
+    DPRINT1("WaitForLSA() called\n");
+
+    hEvent = CreateEventW(NULL,
+                          TRUE,
+                          FALSE,
+                          L"LSA_RPC_SERVER_ACTIVE");
+    if (hEvent == NULL)
+    {
+        dwError = GetLastError();
+        DPRINT1("Failed to create the notication event (Error %lu)\n", dwError);
+
+        if (dwError == ERROR_ALREADY_EXISTS)
+        {
+            hEvent = OpenEventW(SYNCHRONIZE,
+                                FALSE,
+                                L"LSA_RPC_SERVER_ACTIVE");
+            if (hEvent != NULL)
+            {
+               DPRINT1("Could not open the notification event!\n");
+               return;
+            }
+        }
+    }
+
+    DPRINT1("Wait for LSA!\n");
+    WaitForSingleObject(hEvent, INFINITE);
+    DPRINT1("LSA is available!\n");
+
+    CloseHandle(hEvent);
+
+    DPRINT1("WaitForLSA() done\n");
+}
+
+
 DWORD
 ScmCreateServiceDatabase(VOID)
 {
@@ -516,6 +556,9 @@ ScmCreateServiceDatabase(VOID)
 
     RegCloseKey(hServicesKey);
 
+    /* Wait for LSA */
+    WaitForLSA();
+
     /* Delete services that are marked for delete */
     ScmDeleteMarkedServices();
 
index 0a7f61a..199c01b 100644 (file)
@@ -26,14 +26,13 @@ PWLSESSION WLSession = NULL;
 static BOOL
 StartServicesManager(VOID)
 {
-       HANDLE ServicesInitEvent = NULL;
        STARTUPINFOW StartupInfo;
        PROCESS_INFORMATION ProcessInformation;
-       DWORD Count;
        LPCWSTR ServiceString = L"services.exe";
        BOOL res;
 
        /* Start the service control manager (services.exe) */
+       ZeroMemory(&StartupInfo, sizeof(STARTUPINFOW));
        StartupInfo.cb = sizeof(StartupInfo);
        StartupInfo.lpReserved = NULL;
        StartupInfo.lpDesktop = NULL;
@@ -61,29 +60,11 @@ StartServicesManager(VOID)
                return FALSE;
        }
 
-       /* Wait for event creation (by SCM) for max. 20 seconds */
-       for (Count = 0; Count < 20; Count++)
-       {
-               Sleep(1000);
-
-               TRACE("WL: Attempting to open event \"SvcctrlStartEvent_A3752DX\"\n");
-               ServicesInitEvent = OpenEventW(
-                       SYNCHRONIZE,
-                       FALSE,
-                       L"SvcctrlStartEvent_A3752DX");
-               if (ServicesInitEvent)
-                       break;
-       }
+       TRACE("WL: Created new process - %S\n", ServiceString);
 
-       if (!ServicesInitEvent)
-       {
-               ERR("WL: Failed to open event \"SvcctrlStartEvent_A3752DX\"\n");
-               return FALSE;
-       }
+       CloseHandle(ProcessInformation.hThread);
+       CloseHandle(ProcessInformation.hProcess);
 
-       /* Wait for event signalization */
-       WaitForSingleObject(ServicesInitEvent, INFINITE);
-       CloseHandle(ServicesInitEvent);
        TRACE("WL: StartServicesManager() done.\n");
 
        return TRUE;
@@ -99,6 +80,7 @@ StartLsass(VOID)
        BOOL res;
 
        /* Start the service control manager (services.exe) */
+       ZeroMemory(&StartupInfo, sizeof(STARTUPINFOW));
        StartupInfo.cb = sizeof(StartupInfo);
        StartupInfo.lpReserved = NULL;
        StartupInfo.lpDesktop = NULL;
@@ -121,6 +103,11 @@ StartLsass(VOID)
                &StartupInfo,
                &ProcessInformation);
 
+       TRACE("WL: Created new process - %S\n", ServiceString);
+
+       CloseHandle(ProcessInformation.hThread);
+       CloseHandle(ProcessInformation.hProcess);
+
        return res;
 }