#define NDEBUG
#include <debug.h>
+/*
+ * Uncomment the line below to start services
+ * using the SERVICE_START_PENDING state
+ */
+// #define USE_SERVICE_START_PENDING
/* GLOBALS *******************************************************************/
}
-PSERVICE
-ScmGetServiceEntryByClientHandle(HANDLE Handle)
-{
- PLIST_ENTRY ServiceEntry;
- PSERVICE CurrentService;
-
- DPRINT("ScmGetServiceEntryByClientHandle() called\n");
- DPRINT("looking for %p\n", Handle);
-
- ServiceEntry = ServiceListHead.Flink;
- while (ServiceEntry != &ServiceListHead)
- {
- CurrentService = CONTAINING_RECORD(ServiceEntry,
- SERVICE,
- ServiceListEntry);
-
- if (CurrentService->hClient == Handle)
- {
- DPRINT("Found service: '%S'\n", CurrentService->lpDisplayName);
- return CurrentService;
- }
-
- ServiceEntry = ServiceEntry->Flink;
- }
-
- DPRINT("Couldn't find a matching service\n");
-
- return NULL;
-}
-
-
DWORD
ScmCreateNewServiceRecord(LPCWSTR lpServiceName,
PSERVICE *lpServiceRecord)
VOID
ScmDeleteServiceRecord(PSERVICE lpService)
{
- DPRINT1("Deleting Service %S\n", lpService->lpServiceName);
+ DPRINT("Deleting Service %S\n", lpService->lpServiceName);
/* Delete the display name */
if (lpService->lpDisplayName != NULL &&
/* Remove the Service from the List */
RemoveEntryList(&lpService->ServiceListEntry);
- DPRINT1("Deleted Service %S\n", lpService->lpServiceName);
+ DPRINT("Deleted Service %S\n", lpService->lpServiceName);
/* Delete the service record */
HeapFree(GetProcessHeap(), 0, lpService);
- DPRINT1("Done\n");
+ DPRINT("Done\n");
}
return ERROR_NOT_ENOUGH_MEMORY;
ControlPacket->dwControl = dwControl;
- ControlPacket->hClient = Service->hClient;
ControlPacket->dwSize = TotalLength;
+ ControlPacket->hServiceStatus = (SERVICE_STATUS_HANDLE)Service;
wcscpy(&ControlPacket->szArguments[0], Service->lpServiceName);
/* Send the control packet */
return ERROR_NOT_ENOUGH_MEMORY;
ControlPacket->dwControl = SERVICE_CONTROL_START;
- ControlPacket->hClient = Service->hClient;
+ ControlPacket->hServiceStatus = (SERVICE_STATUS_HANDLE)Service;
ControlPacket->dwSize = TotalLength;
Ptr = &ControlPacket->szArguments[0];
wcscpy(Ptr, Service->lpServiceName);
WCHAR NtControlPipeName[MAX_PATH + 1];
HKEY hServiceCurrentKey = INVALID_HANDLE_VALUE;
DWORD KeyDisposition;
+ DWORD dwProcessId;
RtlInitUnicodeString(&ImagePath, NULL);
/* Read SERVICE_STATUS_HANDLE from pipe */
if (!ReadFile(Service->ControlPipeHandle,
- (LPVOID)&Service->hClient,
+ (LPVOID)&dwProcessId,
sizeof(DWORD),
&dwRead,
NULL))
}
else
{
- DPRINT("Received service status %lu\n", Service->hClient);
+ DPRINT("Received service process ID %lu\n", dwProcessId);
/* Send start command */
dwError = ScmSendStartCommand(Service, argc, argv);
/* Load driver */
dwError = ScmLoadDriver(Service);
if (dwError == ERROR_SUCCESS)
+ {
Service->Status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
+ Service->Status.dwCurrentState = SERVICE_RUNNING;
+ }
}
else
{
/* Start user-mode service */
dwError = ScmStartUserModeService(Service, argc, argv);
+ if (dwError == ERROR_SUCCESS)
+ {
+#ifdef USE_SERVICE_START_PENDING
+ Service->Status.dwCurrentState = SERVICE_START_PENDING;
+#else
+ Service->Status.dwCurrentState = SERVICE_RUNNING;
+#endif
+ }
}
DPRINT("ScmStartService() done (Error %lu)\n", dwError);
{
Group->ServicesRunning = TRUE;
}
- Service->Status.dwCurrentState = SERVICE_RUNNING;
}
#if 0
else
DPRINT("ScmGetBootAndSystemDriverState() done\n");
}
+
+BOOL
+ScmLockDatabaseExclusive(VOID)
+{
+ return RtlAcquireResourceExclusive(&DatabaseLock, TRUE);
+}
+
+
+BOOL
+ScmLockDatabaseShared(VOID)
+{
+ return RtlAcquireResourceShared(&DatabaseLock, TRUE);
+}
+
+
+VOID
+ScmUnlockDatabase(VOID)
+{
+ RtlReleaseResource(&DatabaseLock);
+}
+
/* EOF */