[SERVICES]

Revert r49366.

svn path=/trunk/; revision=49371
This commit is contained in:
Eric Kohl 2010-10-31 10:00:21 +00:00
parent 3b08424abb
commit 18ab208eeb
3 changed files with 75 additions and 31 deletions

View file

@ -678,8 +678,64 @@ ScmGetBootAndSystemDriverState(VOID)
DWORD DWORD
ScmSendServiceCommand(PSERVICE Service, ScmControlService(PSERVICE Service,
DWORD dwControl, DWORD dwControl)
{
PSCM_CONTROL_PACKET ControlPacket;
SCM_REPLY_PACKET ReplyPacket;
DWORD dwWriteCount = 0;
DWORD dwReadCount = 0;
DWORD TotalLength;
DWORD dwError = ERROR_SUCCESS;
DPRINT("ScmControlService() called\n");
TotalLength = wcslen(Service->lpServiceName) + 1;
ControlPacket = (SCM_CONTROL_PACKET*)HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(SCM_CONTROL_PACKET) + (TotalLength * sizeof(WCHAR)));
if (ControlPacket == NULL)
return ERROR_NOT_ENOUGH_MEMORY;
ControlPacket->dwControl = dwControl;
ControlPacket->dwSize = TotalLength;
ControlPacket->hServiceStatus = (SERVICE_STATUS_HANDLE)Service;
wcscpy(&ControlPacket->szArguments[0], Service->lpServiceName);
/* Send the control packet */
WriteFile(Service->ControlPipeHandle,
ControlPacket,
sizeof(SCM_CONTROL_PACKET) + (TotalLength * sizeof(WCHAR)),
&dwWriteCount,
NULL);
/* Read the reply */
ReadFile(Service->ControlPipeHandle,
&ReplyPacket,
sizeof(SCM_REPLY_PACKET),
&dwReadCount,
NULL);
/* Release the contol packet */
HeapFree(GetProcessHeap(),
0,
ControlPacket);
if (dwReadCount == sizeof(SCM_REPLY_PACKET))
{
dwError = ReplyPacket.dwError;
}
DPRINT("ScmControlService() done\n");
return dwError;
}
static DWORD
ScmSendStartCommand(PSERVICE Service,
DWORD argc, DWORD argc,
LPWSTR *argv) LPWSTR *argv)
{ {
@ -694,7 +750,7 @@ ScmSendServiceCommand(PSERVICE Service,
DWORD dwError = ERROR_SUCCESS; DWORD dwError = ERROR_SUCCESS;
DWORD i; DWORD i;
DPRINT("ScmSendServiceCommand() called\n"); DPRINT("ScmSendStartCommand() called\n");
/* Calculate the total length of the start command line */ /* Calculate the total length of the start command line */
TotalLength = wcslen(Service->lpServiceName) + 1; TotalLength = wcslen(Service->lpServiceName) + 1;
@ -718,7 +774,7 @@ ScmSendServiceCommand(PSERVICE Service,
if (ControlPacket == NULL) if (ControlPacket == NULL)
return ERROR_NOT_ENOUGH_MEMORY; return ERROR_NOT_ENOUGH_MEMORY;
ControlPacket->dwControl = dwControl; ControlPacket->dwControl = SERVICE_CONTROL_START;
ControlPacket->hServiceStatus = (SERVICE_STATUS_HANDLE)Service; ControlPacket->hServiceStatus = (SERVICE_STATUS_HANDLE)Service;
ControlPacket->dwSize = TotalLength; ControlPacket->dwSize = TotalLength;
Ptr = &ControlPacket->szArguments[0]; Ptr = &ControlPacket->szArguments[0];
@ -763,7 +819,7 @@ ScmSendServiceCommand(PSERVICE Service,
dwError = ReplyPacket.dwError; dwError = ReplyPacket.dwError;
} }
DPRINT("ScmSendServiceCommand() done\n"); DPRINT("ScmSendStartCommand() done\n");
return dwError; return dwError;
} }
@ -942,10 +998,7 @@ ScmStartUserModeService(PSERVICE Service,
DPRINT("Received service process ID %lu\n", dwProcessId); DPRINT("Received service process ID %lu\n", dwProcessId);
/* Send start command */ /* Send start command */
dwError = ScmSendServiceCommand(Service, dwError = ScmSendStartCommand(Service, argc, argv);
SERVICE_CONTROL_START,
argc,
argv);
} }
} }
else else
@ -1174,10 +1227,7 @@ ScmAutoShutdownServices(VOID)
CurrentService->Status.dwCurrentState == SERVICE_START_PENDING) CurrentService->Status.dwCurrentState == SERVICE_START_PENDING)
{ {
/* shutdown service */ /* shutdown service */
ScmSendServiceCommand(CurrentService, ScmControlService(CurrentService, SERVICE_CONTROL_STOP);
SERVICE_CONTROL_STOP,
0,
NULL);
} }
ServiceEntry = ServiceEntry->Flink; ServiceEntry = ServiceEntry->Flink;

View file

@ -699,10 +699,8 @@ DWORD RControlService(
} }
/* Send control code to the service */ /* Send control code to the service */
dwError = ScmSendServiceCommand(lpService, dwError = ScmControlService(lpService,
dwControl, dwControl);
0,
NULL);
/* Return service status information */ /* Return service status information */
RtlCopyMemory(lpServiceStatus, RtlCopyMemory(lpServiceStatus,
@ -2866,10 +2864,7 @@ DWORD RStartServiceW(
} }
/* Start the service */ /* Start the service */
dwError = ScmSendServiceCommand(lpService, dwError = ScmStartService(lpService, argc, (LPWSTR *)argv);
SERVICE_CONTROL_START,
argc,
(LPWSTR *)argv);
return dwError; return dwError;
} }
@ -4077,10 +4072,7 @@ DWORD RStartServiceA(
/* FIXME: Convert argument vector to Unicode */ /* FIXME: Convert argument vector to Unicode */
/* Start the service */ /* Start the service */
dwError = ScmSendServiceCommand(lpService, dwError = ScmStartService(lpService, 0, NULL);
SERVICE_CONTROL_START,
0,
NULL);
/* FIXME: Free argument vector */ /* FIXME: Free argument vector */

View file

@ -104,8 +104,7 @@ VOID ScmShutdownServiceDatabase(VOID);
VOID ScmGetBootAndSystemDriverState(VOID); VOID ScmGetBootAndSystemDriverState(VOID);
VOID ScmAutoStartServices(VOID); VOID ScmAutoStartServices(VOID);
VOID ScmAutoShutdownServices(VOID); VOID ScmAutoShutdownServices(VOID);
DWORD ScmSendServiceCommand(PSERVICE Service, DWORD ScmStartService(PSERVICE Service,
DWORD dwControl,
DWORD argc, DWORD argc,
LPWSTR *argv); LPWSTR *argv);
@ -117,6 +116,9 @@ DWORD ScmCreateNewServiceRecord(LPCWSTR lpServiceName,
VOID ScmDeleteServiceRecord(PSERVICE lpService); VOID ScmDeleteServiceRecord(PSERVICE lpService);
DWORD ScmMarkServiceForDelete(PSERVICE pService); DWORD ScmMarkServiceForDelete(PSERVICE pService);
DWORD ScmControlService(PSERVICE Service,
DWORD dwControl);
BOOL ScmLockDatabaseExclusive(VOID); BOOL ScmLockDatabaseExclusive(VOID);
BOOL ScmLockDatabaseShared(VOID); BOOL ScmLockDatabaseShared(VOID);
VOID ScmUnlockDatabase(VOID); VOID ScmUnlockDatabase(VOID);