OpenSCManager waits for services.exe to initialize

svn path=/trunk/; revision=3295
This commit is contained in:
Jurgen van Gael 2002-07-23 08:16:05 +00:00
parent 57a74268f7
commit 3ce45b038f

View file

@ -1,4 +1,4 @@
/* $Id: scm.c,v 1.9 2002/07/20 13:31:34 ekohl Exp $
/* $Id: scm.c,v 1.10 2002/07/23 08:16:05 jvangael Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -407,28 +407,41 @@ OpenSCManagerA(LPCSTR lpMachineName,
/**********************************************************************
* OpenSCManagerW
*/
SC_HANDLE STDCALL
OpenSCManagerW(LPCWSTR lpMachineName,
SC_HANDLE STDCALL OpenSCManagerW(LPCWSTR lpMachineName,
LPCWSTR lpDatabaseName,
DWORD dwDesiredAccess)
{
HANDLE hPipe;
DWORD dwMode;
DWORD dwWait;
BOOL fSuccess;
HANDLE hStartEvent;
LPWSTR lpszPipeName = L"\\\\.\\pipe\\Ntsvcs";
if(lpMachineName == NULL || wcslen(lpMachineName) == 0)
{
if(lpDatabaseName != NULL && wcscmp(lpDatabaseName, SERVICES_ACTIVE_DATABASEW) != 0)
{ return(NULL); }
// Only connect to scm when event "SvcctrlStartEvent_A3725DX" is signaled
hStartEvent = OpenEvent(SYNCHRONIZE, FALSE, _T("SvcctrlStartEvent_A3725DX"));
if(hStartEvent == NULL)
{
SetLastError(ERROR_DATABASE_DOES_NOT_EXIST);
return (NULL);
}
dwWait = WaitForSingleObject(hStartEvent, INFINITE);
if(dwWait == WAIT_FAILED)
{
SetLastError(ERROR_ACCESS_DENIED);
return (NULL);
}
CloseHandle(hStartEvent);
// Try to open a named pipe; wait for it, if necessary
while(1)
{
hPipe = CreateFileW(
lpszPipeName, // pipe name
hPipe = CreateFileW(lpszPipeName, // pipe name
dwDesiredAccess,
0, // no sharing
NULL, // no security attributes
@ -437,27 +450,19 @@ OpenSCManagerW(LPCWSTR lpMachineName,
NULL); // no template file
// Break if the pipe handle is valid
if(hPipe != INVALID_HANDLE_VALUE)
break;
// Exit if an error other than ERROR_PIPE_BUSY occurs
if(GetLastError()!= ERROR_PIPE_BUSY)
{
return(NULL);
}
{ return(NULL); }
// All pipe instances are busy, so wait for 20 seconds
if(!WaitNamedPipeW(lpszPipeName, 20000))
{
return(NULL);
}
{ return(NULL); }
}
// The pipe connected; change to message-read mode
dwMode = PIPE_READMODE_MESSAGE;
fSuccess = SetNamedPipeHandleState(
hPipe, // pipe handle
@ -471,7 +476,6 @@ OpenSCManagerW(LPCWSTR lpMachineName,
}
#if 0
// Send a message to the pipe server
lpvMessage = (argc > 1) ? argv[1] : "default message";
fSuccess = WriteFile(
@ -489,7 +493,6 @@ OpenSCManagerW(LPCWSTR lpMachineName,
do
{
// Read from the pipe
fSuccess = ReadFile(
hPipe, // pipe handle
chBuf, // buffer to receive reply
@ -501,14 +504,10 @@ OpenSCManagerW(LPCWSTR lpMachineName,
break;
// Reply from the pipe is written to STDOUT.
if (!WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),
chBuf, cbRead, &cbWritten, NULL))
{
if(!WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), chBuf, cbRead, &cbWritten, NULL))
break;
}
} while(!fSuccess); // repeat loop if ERROR_MORE_DATA
//CloseHandle(hPipe);
#endif
return(hPipe);