Author: gedmurphy
Date: Tue Sep 11 16:56:22 2007
New Revision: 29004
URL:
http://svn.reactos.org/svn/reactos?rev=29004&view=rev
Log:
- store the SERVICE_STATUS_HANDLE and use it for setting service status
- add functionality for controlling services
Modified:
trunk/reactos/base/system/services/database.c
trunk/reactos/base/system/services/rpcserver.c
trunk/reactos/base/system/services/services.h
Modified: trunk/reactos/base/system/services/database.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/datab…
==============================================================================
--- trunk/reactos/base/system/services/database.c (original)
+++ trunk/reactos/base/system/services/database.c Tue Sep 11 16:56:22 2007
@@ -27,6 +27,7 @@
/* FUNCTIONS *****************************************************************/
+
PSERVICE
ScmGetServiceEntryByName(LPWSTR lpServiceName)
{
@@ -115,13 +116,13 @@
PSERVICE
-ScmGetServiceEntryByThreadId(ULONG ThreadId)
+ScmGetServiceEntryByServiceStatusHandle(ULONG Handle)
{
PLIST_ENTRY ServiceEntry;
PSERVICE CurrentService;
- DPRINT("ScmGetServiceEntryByThreadId() called\n");
- DPRINT("Finding ThreadId %lu\n", ThreadId);
+ DPRINT("ScmGetServiceEntryByServiceStatusHandle() called\n");
+ DPRINT("looking for %lu\n", Handle);
ServiceEntry = ServiceListHead.Flink;
while (ServiceEntry != &ServiceListHead)
@@ -129,10 +130,10 @@
CurrentService = CONTAINING_RECORD(ServiceEntry,
SERVICE,
ServiceListEntry);
- DPRINT("Found threadId %lu\n", CurrentService->ThreadId);
- if (CurrentService->ThreadId == ThreadId)
- {
- DPRINT("Found service: '%S'\n",
CurrentService->lpDisplayName);
+
+ if (CurrentService->hServiceStatus == Handle)
+ {
+ DPRINT1("Found service: '%S'\n",
CurrentService->lpDisplayName);
return CurrentService;
}
@@ -567,21 +568,27 @@
{
PSCM_CONTROL_PACKET ControlPacket;
DWORD Count;
+ DWORD TotalLength;
DPRINT("ScmControlService() called\n");
- ControlPacket = (SCM_CONTROL_PACKET*) HeapAlloc(GetProcessHeap(),
- HEAP_ZERO_MEMORY,
- sizeof(SCM_CONTROL_PACKET));
+ 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;
+ wcscpy(&ControlPacket->szArguments[0], Service->lpServiceName);
/* Send the start command */
WriteFile(Service->ControlPipeHandle,
ControlPacket,
- sizeof(SCM_CONTROL_PACKET),
+ sizeof(SCM_CONTROL_PACKET) + (TotalLength * sizeof(WCHAR)),
&Count,
NULL);
@@ -591,6 +598,10 @@
HeapFree(GetProcessHeap(),
0,
ControlPacket);
+
+ RtlCopyMemory(lpServiceStatus,
+ &Service->Status,
+ sizeof(SERVICE_STATUS));
DPRINT("ScmControlService) done\n");
@@ -609,7 +620,7 @@
PWSTR Ptr;
DWORD Count;
- DPRINT("ScmSendStartCommand() called\n");
+ DPRINT1("ScmSendStartCommand() called\n");
/* Calculate the total length of the start command line */
TotalLength = wcslen(Service->lpServiceName) + 1;
@@ -776,14 +787,13 @@
if (ConnectNamedPipe(Service->ControlPipeHandle, NULL) ?
TRUE : (dwError = GetLastError()) == ERROR_PIPE_CONNECTED)
{
- DWORD dwProcessId = 0;
DWORD dwRead = 0;
DPRINT("Control pipe connected!\n");
- /* Read thread id from pipe */
+ /* Read SERVICE_STATUS_HANDLE from pipe */
if (!ReadFile(Service->ControlPipeHandle,
- (LPVOID)&dwProcessId,
+ (LPVOID)&Service->hServiceStatus,
sizeof(DWORD),
&dwRead,
NULL))
@@ -794,7 +804,8 @@
}
else
{
- DPRINT("Received process id %lu\n", dwProcessId);
+ DPRINT("Received service status %lu\n",
Service->hServiceStatus);
+ DPRINT("calling ScmSendStartCommand on %S\n",
Service->lpDisplayName);
/* Send start command */
dwError = ScmSendStartCommand(Service, lpArgs);
Modified: trunk/reactos/base/system/services/rpcserver.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/rpcse…
==============================================================================
--- trunk/reactos/base/system/services/rpcserver.c (original)
+++ trunk/reactos/base/system/services/rpcserver.c Tue Sep 11 16:56:22 2007
@@ -717,7 +717,7 @@
if (ScmShutdown)
return ERROR_SHUTDOWN_IN_PROGRESS;
- lpService = ScmGetServiceEntryByThreadId((ULONG)hServiceStatus);
+ lpService = ScmGetServiceEntryByServiceStatusHandle((ULONG)hServiceStatus);
if (lpService == NULL)
{
DPRINT1("lpService == NULL!\n");
Modified: trunk/reactos/base/system/services/services.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/servi…
==============================================================================
--- trunk/reactos/base/system/services/services.h (original)
+++ trunk/reactos/base/system/services/services.h Tue Sep 11 16:56:22 2007
@@ -41,6 +41,7 @@
BOOL bDeleted;
DWORD dwResumeCount;
+ SERVICE_STATUS_HANDLE hServiceStatus;
SERVICE_STATUS Status;
DWORD dwStartType;
DWORD dwErrorControl;
@@ -104,7 +105,7 @@
PSERVICE ScmGetServiceEntryByName(LPWSTR lpServiceName);
PSERVICE ScmGetServiceEntryByDisplayName(LPWSTR lpDisplayName);
PSERVICE ScmGetServiceEntryByResumeCount(DWORD dwResumeCount);
-PSERVICE ScmGetServiceEntryByThreadId(ULONG ThreadId);
+PSERVICE ScmGetServiceEntryByServiceStatusHandle(ULONG ThreadId);
DWORD ScmCreateNewServiceRecord(LPWSTR lpServiceName,
PSERVICE *lpServiceRecord);
DWORD ScmMarkServiceForDelete(PSERVICE pService);