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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -407,28 +407,41 @@ OpenSCManagerA(LPCSTR lpMachineName,
/********************************************************************** /**********************************************************************
* OpenSCManagerW * OpenSCManagerW
*/ */
SC_HANDLE STDCALL SC_HANDLE STDCALL OpenSCManagerW(LPCWSTR lpMachineName,
OpenSCManagerW(LPCWSTR lpMachineName,
LPCWSTR lpDatabaseName, LPCWSTR lpDatabaseName,
DWORD dwDesiredAccess) DWORD dwDesiredAccess)
{ {
HANDLE hPipe; HANDLE hPipe;
DWORD dwMode; DWORD dwMode;
DWORD dwWait;
BOOL fSuccess; BOOL fSuccess;
HANDLE hStartEvent;
LPWSTR lpszPipeName = L"\\\\.\\pipe\\Ntsvcs"; LPWSTR lpszPipeName = L"\\\\.\\pipe\\Ntsvcs";
if(lpMachineName == NULL || wcslen(lpMachineName) == 0) if(lpMachineName == NULL || wcslen(lpMachineName) == 0)
{ {
if(lpDatabaseName != NULL && wcscmp(lpDatabaseName, SERVICES_ACTIVE_DATABASEW) != 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); 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 // Try to open a named pipe; wait for it, if necessary
while(1) while(1)
{ {
hPipe = CreateFileW( hPipe = CreateFileW(lpszPipeName, // pipe name
lpszPipeName, // pipe name
dwDesiredAccess, dwDesiredAccess,
0, // no sharing 0, // no sharing
NULL, // no security attributes NULL, // no security attributes
@ -437,27 +450,19 @@ OpenSCManagerW(LPCWSTR lpMachineName,
NULL); // no template file NULL); // no template file
// Break if the pipe handle is valid // Break if the pipe handle is valid
if(hPipe != INVALID_HANDLE_VALUE) if(hPipe != INVALID_HANDLE_VALUE)
break; break;
// Exit if an error other than ERROR_PIPE_BUSY occurs // Exit if an error other than ERROR_PIPE_BUSY occurs
if(GetLastError()!= ERROR_PIPE_BUSY) if(GetLastError()!= ERROR_PIPE_BUSY)
{ { return(NULL); }
return(NULL);
}
// All pipe instances are busy, so wait for 20 seconds // All pipe instances are busy, so wait for 20 seconds
if(!WaitNamedPipeW(lpszPipeName, 20000)) if(!WaitNamedPipeW(lpszPipeName, 20000))
{ { return(NULL); }
return(NULL);
}
} }
// The pipe connected; change to message-read mode // The pipe connected; change to message-read mode
dwMode = PIPE_READMODE_MESSAGE; dwMode = PIPE_READMODE_MESSAGE;
fSuccess = SetNamedPipeHandleState( fSuccess = SetNamedPipeHandleState(
hPipe, // pipe handle hPipe, // pipe handle
@ -471,7 +476,6 @@ OpenSCManagerW(LPCWSTR lpMachineName,
} }
#if 0 #if 0
// Send a message to the pipe server // Send a message to the pipe server
lpvMessage = (argc > 1) ? argv[1] : "default message"; lpvMessage = (argc > 1) ? argv[1] : "default message";
fSuccess = WriteFile( fSuccess = WriteFile(
@ -489,7 +493,6 @@ OpenSCManagerW(LPCWSTR lpMachineName,
do do
{ {
// Read from the pipe // Read from the pipe
fSuccess = ReadFile( fSuccess = ReadFile(
hPipe, // pipe handle hPipe, // pipe handle
chBuf, // buffer to receive reply chBuf, // buffer to receive reply
@ -501,14 +504,10 @@ OpenSCManagerW(LPCWSTR lpMachineName,
break; break;
// Reply from the pipe is written to STDOUT. // 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; break;
}
} while(!fSuccess); // repeat loop if ERROR_MORE_DATA } while(!fSuccess); // repeat loop if ERROR_MORE_DATA
//CloseHandle(hPipe); //CloseHandle(hPipe);
#endif #endif
return(hPipe); return(hPipe);