[SERVICES] When autostart services are up, signal an event.
authorEric Kohl <eric.kohl@reactos.org>
Sat, 20 Feb 2010 13:04:56 +0000 (13:04 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 20 Feb 2010 13:04:56 +0000 (13:04 +0000)
[SYSSETUP] Wait until all autostart services are up. Bug #4194.

Patches by Dmitry Gorbachev.
See issue #4142 for more details.

svn path=/trunk/; revision=45633

reactos/base/system/services/services.c
reactos/dll/win32/syssetup/install.c

index 44ee8f3..0c5327d 100644 (file)
@@ -48,35 +48,34 @@ PrintString(LPCSTR fmt, ...)
 
 
 BOOL
-ScmCreateStartEvent(PHANDLE StartEvent)
+ScmCreateEvent(PHANDLE Event,
+               LPCWSTR Name)
 {
     HANDLE hEvent;
 
-    hEvent = CreateEvent(NULL,
-                         TRUE,
-                         FALSE,
-                         TEXT("SvcctrlStartEvent_A3752DX"));
+    hEvent = CreateEventW(NULL,
+                          TRUE,
+                          FALSE,
+                          Name);
     if (hEvent == NULL)
     {
         if (GetLastError() == ERROR_ALREADY_EXISTS)
         {
-            hEvent = OpenEvent(EVENT_ALL_ACCESS,
-                               FALSE,
-                               TEXT("SvcctrlStartEvent_A3752DX"));
-            if (hEvent == NULL)
-            {
-                return FALSE;
-            }
-        }
-        else
-        {
-            return FALSE;
+            hEvent = OpenEventW(EVENT_ALL_ACCESS,
+                                FALSE,
+                                Name);
         }
     }
 
-    *StartEvent = hEvent;
+    if (hEvent)
+    {
+        DPRINT("SERVICES: created event %S with handle %x\n", Name, hEvent);
+        *Event = hEvent;
+        return TRUE;
+    }
 
-    return TRUE;
+    DPRINT1("SERVICES: Failed to create event %S\n", Name);
+    return FALSE;
 }
 
 
@@ -299,6 +298,7 @@ wWinMain(HINSTANCE hInstance,
          int nShowCmd)
 {
     HANDLE hScmStartEvent;
+    HANDLE hScmAutoStartCompleteEvent;
     HANDLE hEvent;
     DWORD dwError;
 
@@ -307,14 +307,16 @@ wWinMain(HINSTANCE hInstance,
     /* Acquire privileges to load drivers */
     AcquireLoadDriverPrivilege();
 
-    /* Create start event */
-    if (!ScmCreateStartEvent(&hScmStartEvent))
+    /* Create events */
+    if (!ScmCreateEvent(&hScmAutoStartCompleteEvent, L"SC_AutoStartComplete"))
     {
-        DPRINT1("SERVICES: Failed to create start event\n");
         ExitThread(0);
     }
 
-    DPRINT("SERVICES: created start event with handle %x.\n", hScmStartEvent);
+    if (!ScmCreateEvent(&hScmStartEvent, L"SvcctrlStartEvent_A3752DX"))
+    {
+        ExitThread(0);
+    }
 
 //    ScmInitThreadManager();
 
@@ -354,6 +356,9 @@ wWinMain(HINSTANCE hInstance,
 
     DPRINT("SERVICES: Running.\n");
 
+    /* Signal complete event */
+    SetEvent(hScmAutoStartCompleteEvent);
+
 #if 1
     hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
     if (hEvent)
index b3bd427..f2d3239 100644 (file)
@@ -481,9 +481,20 @@ EnableUserModePnpManager(VOID)
     DWORD BytesNeeded = 0;
     DWORD dwWaitTime;
     DWORD dwMaxWait;
+    HANDLE hEvent;
     BOOL ret = FALSE;
 
-    hSCManager = OpenSCManager(NULL, NULL, 0);
+    hEvent = OpenEventW(EVENT_ALL_ACCESS,
+                        FALSE,
+                        L"SC_AutoStartComplete");
+    if (hEvent == NULL)
+        goto cleanup;
+
+    WaitForSingleObject(hEvent, INFINITE);
+
+    hSCManager = OpenSCManager(NULL,
+                               NULL,
+                               SC_MANAGER_CONNECT);
     if (hSCManager == NULL)
         goto cleanup;