[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
This commit is contained in:
Eric Kohl 2012-07-08 23:08:19 +00:00
parent aec110d514
commit 84b02d3d64
3 changed files with 11 additions and 11 deletions

View file

@ -22,9 +22,9 @@ static PSTART_LOCK pServiceStartLock = NULL;
/* FUNCTIONS *****************************************************************/ /* 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 DWORD
ScmAcquireServiceStartLock(IN BOOL IsServiceController, ScmAcquireServiceStartLock(IN BOOL IsServiceController,
OUT LPSC_RPC_LOCK lpLock) OUT LPSC_RPC_LOCK lpLock)
@ -146,7 +146,7 @@ ScmQueryServiceLockStatusW(OUT LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus)
lpLockStatus->dwLockDuration = 0; lpLockStatus->dwLockDuration = 0;
} }
/* Unlock the whole SC manager */ /* Unlock the service database */
ScmUnlockDatabase(); ScmUnlockDatabase();
return; return;
@ -178,7 +178,7 @@ ScmQueryServiceLockStatusA(OUT LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus)
lpLockStatus->dwLockDuration = 0; lpLockStatus->dwLockDuration = 0;
} }
/* Unlock the whole SC manager */ /* Unlock the service database */
ScmUnlockDatabase(); ScmUnlockDatabase();
return; return;

View file

@ -2877,7 +2877,7 @@ DWORD RQueryServiceLockStatusW(
return ERROR_ACCESS_DENIED; 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); dwRequiredSize = sizeof(QUERY_SERVICE_LOCK_STATUSW) + sizeof(WCHAR);
*pcbBytesNeeded = dwRequiredSize; *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 */ /* Acquire the service start lock until the service has been started */
dwError = ScmAcquireServiceStartLock(TRUE, &Lock); dwError = ScmAcquireServiceStartLock(TRUE, &Lock);
if (dwError != ERROR_SUCCESS) if (dwError != ERROR_SUCCESS)
goto done; goto done;
/* Start the service */ /* Start the service */
dwError = ScmStartService(lpService, argc, lpVector); dwError = ScmStartService(lpService, argc, lpVector);
/* Release the service start lock */ /* Release the service start lock */
ScmReleaseServiceStartLock(&Lock); ScmReleaseServiceStartLock(&Lock);

View file

@ -378,6 +378,7 @@ wWinMain(HINSTANCE hInstance,
{ {
HANDLE hScmStartEvent = NULL; HANDLE hScmStartEvent = NULL;
SC_RPC_LOCK Lock = NULL; SC_RPC_LOCK Lock = NULL;
BOOL bDeleteCriticalSection = FALSE;
DWORD dwError; DWORD dwError;
DPRINT("SERVICES: Service Control Manager\n"); DPRINT("SERVICES: Service Control Manager\n");
@ -442,6 +443,7 @@ wWinMain(HINSTANCE hInstance,
AcquireLoadDriverPrivilege(); AcquireLoadDriverPrivilege();
ScmInitNamedPipeCriticalSection(); ScmInitNamedPipeCriticalSection();
bDeleteCriticalSection = TRUE;
/* Acquire the service start lock until autostart services have been started */ /* Acquire the service start lock until autostart services have been started */
dwError = ScmAcquireServiceStartLock(TRUE, &Lock); dwError = ScmAcquireServiceStartLock(TRUE, &Lock);
@ -465,7 +467,8 @@ wWinMain(HINSTANCE hInstance,
WaitForSingleObject(hScmShutdownEvent, INFINITE); WaitForSingleObject(hScmShutdownEvent, INFINITE);
done: done:
ScmDeleteNamedPipeCriticalSection(); if (bDeleteCriticalSection == TRUE)
ScmDeleteNamedPipeCriticalSection();
/* Close the shutdown event */ /* Close the shutdown event */
if (hScmShutdownEvent != NULL) if (hScmShutdownEvent != NULL)