Author: gbrunmar
Date: Mon Oct 22 23:54:51 2007
New Revision: 29793
URL:
http://svn.reactos.org/svn/reactos?rev=29793&view=rev
Log:
More svchost stub, end-of-the-day checkin.
Modified:
trunk/reactos/base/services/svchost/svchost.c
Modified: trunk/reactos/base/services/svchost/svchost.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/svchost/svch…
==============================================================================
--- trunk/reactos/base/services/svchost/svchost.c (original)
+++ trunk/reactos/base/services/svchost/svchost.c Mon Oct 22 23:54:51 2007
@@ -139,7 +139,7 @@
return TRUE;
}
-BOOL FreeServices()
+VOID FreeServices()
{
while (FirstService)
{
@@ -151,11 +151,12 @@
HeapFree(GetProcessHeap(), 0, Service->Name);
HeapFree(GetProcessHeap(), 0, Service);
}
-
- return TRUE;
-}
-
-BOOL LoadServiceCategory(LPCTSTR ServiceCategory)
+}
+
+/*
+ * Returns the number of services successfully loaded from the category
+ */
+DWORD LoadServiceCategory(LPCTSTR ServiceCategory)
{
HKEY hServicesKey;
DWORD KeyType;
@@ -163,19 +164,20 @@
TCHAR Buffer[REG_MAX_DATA_SIZE];
LPCTSTR ServiceName;
DWORD BufferIndex = 0;
+ DWORD NrOfServices = 0;
/* Get all the services in this category */
if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, SVCHOST_REG_KEY, 0, KEY_READ,
&hServicesKey))
{
DPRINT1("Could not open service category: %s\n", ServiceCategory);
- return FALSE;
+ return 0;
}
if (ERROR_SUCCESS != RegQueryValueEx(hServicesKey, ServiceCategory, NULL, &KeyType,
(LPBYTE)Buffer, &BufferSize))
{
DPRINT1("Could not open service category (2): %s\n", ServiceCategory);
RegCloseKey(hServicesKey);
- return FALSE;
+ return 0;
}
/* Clean up */
@@ -191,18 +193,23 @@
if (0 == Length)
break;
- PrepareService(ServiceName);
+ if (TRUE == PrepareService(ServiceName))
+ ++NrOfServices;
BufferIndex += (Length + 1) * sizeof(TCHAR);
ServiceName = &Buffer[BufferIndex];
}
- return TRUE;
+ return NrOfServices;
}
int _tmain (int argc, LPTSTR argv [])
{
+ DWORD NrOfServices;
+ LPSERVICE_TABLE_ENTRY ServiceTable;
+ DWORD i;
+
if (argc < 3)
{
/* MS svchost.exe doesn't seem to print help, should we? */
@@ -215,7 +222,32 @@
return 1;
}
- LoadServiceCategory(argv[2]);
+ NrOfServices = LoadServiceCategory(argv[2]);
+
+ if (0 == NrOfServices)
+ return 1;
+
+ ServiceTable = HeapAlloc(GetProcessHeap(), 0, sizeof(SERVICE_TABLE_ENTRY) *
(NrOfServices + 1));
+
+ if (NULL != ServiceTable)
+ {
+ PSERVICE Service = FirstService;
+
+ for (i = 0; i < NrOfServices; ++i)
+ {
+ ServiceTable[i].lpServiceName = Service->Name;
+ ServiceTable[i].lpServiceProc = Service->ServiceMainFunc;
+ Service = Service->Next;
+ }
+
+ StartServiceCtrlDispatcher(ServiceTable);
+
+ HeapFree(GetProcessHeap(), 0, ServiceTable);
+ }
+ else
+ {
+ DPRINT1("Not enough memory for the service table, trying to allocate %u
bytes\n", sizeof(SERVICE_TABLE_ENTRY) * (NrOfServices + 1));
+ }
FreeServices();