From 84b02d3d642b718fec8b050a03819c283e4eff57 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 8 Jul 2012 23:08:19 +0000 Subject: [PATCH] [SERVICES] Correct comments and code error introduced in rev 56844. Patch by Hermes Belusca. I used a helper variable to determine whether or not ScmDeleteNamedPipeCriticalSection must be called. Changing the order in which functions are called could cause a deadlock. See issue #7172 for more details. svn path=/trunk/; revision=56861 --- reactos/base/system/services/lock.c | 8 ++++---- reactos/base/system/services/rpcserver.c | 9 +++------ reactos/base/system/services/services.c | 5 ++++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/reactos/base/system/services/lock.c b/reactos/base/system/services/lock.c index b65d734d95e..1f27d80dc8f 100644 --- a/reactos/base/system/services/lock.c +++ b/reactos/base/system/services/lock.c @@ -22,9 +22,9 @@ static PSTART_LOCK pServiceStartLock = NULL; /* FUNCTIONS *****************************************************************/ /* - * TRUE if locked by the Service Control Manager, FALSE otherwise + * NOTE: IsServiceController is TRUE if locked by the + * Service Control Manager, and FALSE otherwise. */ - DWORD ScmAcquireServiceStartLock(IN BOOL IsServiceController, OUT LPSC_RPC_LOCK lpLock) @@ -146,7 +146,7 @@ ScmQueryServiceLockStatusW(OUT LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus) lpLockStatus->dwLockDuration = 0; } - /* Unlock the whole SC manager */ + /* Unlock the service database */ ScmUnlockDatabase(); return; @@ -178,7 +178,7 @@ ScmQueryServiceLockStatusA(OUT LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus) lpLockStatus->dwLockDuration = 0; } - /* Unlock the whole SC manager */ + /* Unlock the service database */ ScmUnlockDatabase(); return; diff --git a/reactos/base/system/services/rpcserver.c b/reactos/base/system/services/rpcserver.c index a4a91db1ed3..d811ee60c42 100644 --- a/reactos/base/system/services/rpcserver.c +++ b/reactos/base/system/services/rpcserver.c @@ -2877,7 +2877,7 @@ DWORD RQueryServiceLockStatusW( return ERROR_ACCESS_DENIED; } - /* HACK: we need to compute instead the real length of the owner name */ + /* FIXME: we need to compute instead the real length of the owner name */ dwRequiredSize = sizeof(QUERY_SERVICE_LOCK_STATUSW) + sizeof(WCHAR); *pcbBytesNeeded = dwRequiredSize; @@ -4243,16 +4243,13 @@ DWORD RStartServiceA( } } - /* Start the service */ - dwError = ScmStartService(lpService, argc, lpVector); - /* Acquire the service start lock until the service has been started */ dwError = ScmAcquireServiceStartLock(TRUE, &Lock); if (dwError != ERROR_SUCCESS) goto done; - /* Start the service */ - dwError = ScmStartService(lpService, argc, lpVector); + /* Start the service */ + dwError = ScmStartService(lpService, argc, lpVector); /* Release the service start lock */ ScmReleaseServiceStartLock(&Lock); diff --git a/reactos/base/system/services/services.c b/reactos/base/system/services/services.c index 85720101110..ca7401e5fc0 100644 --- a/reactos/base/system/services/services.c +++ b/reactos/base/system/services/services.c @@ -378,6 +378,7 @@ wWinMain(HINSTANCE hInstance, { HANDLE hScmStartEvent = NULL; SC_RPC_LOCK Lock = NULL; + BOOL bDeleteCriticalSection = FALSE; DWORD dwError; DPRINT("SERVICES: Service Control Manager\n"); @@ -442,6 +443,7 @@ wWinMain(HINSTANCE hInstance, AcquireLoadDriverPrivilege(); ScmInitNamedPipeCriticalSection(); + bDeleteCriticalSection = TRUE; /* Acquire the service start lock until autostart services have been started */ dwError = ScmAcquireServiceStartLock(TRUE, &Lock); @@ -465,7 +467,8 @@ wWinMain(HINSTANCE hInstance, WaitForSingleObject(hScmShutdownEvent, INFINITE); done: - ScmDeleteNamedPipeCriticalSection(); + if (bDeleteCriticalSection == TRUE) + ScmDeleteNamedPipeCriticalSection(); /* Close the shutdown event */ if (hScmShutdownEvent != NULL)