[SERVICES]
authorAleksey Bragin <aleksey@reactos.org>
Sun, 27 Feb 2011 23:07:04 +0000 (23:07 +0000)
committerAleksey Bragin <aleksey@reactos.org>
Sun, 27 Feb 2011 23:07:04 +0000 (23:07 +0000)
- Protect whole contents of ScmStartService() with a critical section instead of just a few parts of ScmStartUserModeService(). Seems to fix the comment #8 issue of bug #5924.

svn path=/trunk/; revision=50930

reactos/base/system/services/database.c

index ed0bdcb..9a332a0 100644 (file)
@@ -922,8 +922,6 @@ ScmStartUserModeService(PSERVICE Service,
         return Status;
     }
 
-    EnterCriticalSection(&StartServiceCriticalSection);
-
     /* Create '\\.\pipe\net\NtControlPipeXXX' instance */
     swprintf(NtControlPipeName, L"\\\\.\\pipe\\net\\NtControlPipe%u", ServiceCurrent);
     Service->ControlPipeHandle = CreateNamedPipeW(NtControlPipeName,
@@ -938,7 +936,6 @@ ScmStartUserModeService(PSERVICE Service,
     if (Service->ControlPipeHandle == INVALID_HANDLE_VALUE)
     {
         DPRINT1("Failed to create control pipe!\n");
-        LeaveCriticalSection(&StartServiceCriticalSection);
         return GetLastError();
     }
 
@@ -970,7 +967,6 @@ ScmStartUserModeService(PSERVICE Service,
         Service->ControlPipeHandle = INVALID_HANDLE_VALUE;
 
         DPRINT1("Starting '%S' failed!\n", Service->lpServiceName);
-        LeaveCriticalSection(&StartServiceCriticalSection);
         return dwError;
     }
 
@@ -1030,8 +1026,6 @@ ScmStartUserModeService(PSERVICE Service,
     CloseHandle(ProcessInformation.hThread);
     CloseHandle(ProcessInformation.hProcess);
 
-    LeaveCriticalSection(&StartServiceCriticalSection);
-
     return dwError;
 }
 
@@ -1042,6 +1036,8 @@ ScmStartService(PSERVICE Service, DWORD argc, LPWSTR *argv)
     PSERVICE_GROUP Group = Service->lpGroup;
     DWORD dwError = ERROR_SUCCESS;
 
+    EnterCriticalSection(&StartServiceCriticalSection);
+
     DPRINT("ScmStartService() called\n");
 
     Service->ControlPipeHandle = INVALID_HANDLE_VALUE;
@@ -1072,6 +1068,7 @@ ScmStartService(PSERVICE Service, DWORD argc, LPWSTR *argv)
     }
 
     DPRINT("ScmStartService() done (Error %lu)\n", dwError);
+    LeaveCriticalSection(&StartServiceCriticalSection);
 
     if (dwError == ERROR_SUCCESS)
     {