Fixed some minor things with (yet unused) svchost
authorGregor Brunmar <gbrunmar.ros@gmail.com>
Mon, 3 Dec 2007 18:24:05 +0000 (18:24 +0000)
committerGregor Brunmar <gbrunmar.ros@gmail.com>
Mon, 3 Dec 2007 18:24:05 +0000 (18:24 +0000)
svn path=/trunk/; revision=30985

reactos/base/services/svchost/svchost.c

index 9cc88cf..2e9276b 100644 (file)
@@ -102,11 +102,12 @@ BOOL PrepareService(LPCTSTR ServiceName)
        HeapFree(GetProcessHeap(), 0, Buffer);
 
        /* Load the service dll */
+       DPRINT1("Trying to load dll\n");
        hServiceDll = LoadLibrary(DllPath);
 
        if (NULL == hServiceDll)
        {
-               DPRINT1("Unable to load ServiceDll: %s\n", DllPath);
+               DPRINT1("Unable to load ServiceDll: %s, ErrorCode: %u\n", DllPath, GetLastError());
                return FALSE;
        }
 
@@ -208,39 +209,47 @@ 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? */
-               return 1;
+               return 0;
        }
 
        if (_tcscmp(argv[1], _T("-k")) != 0)
        {
                /* For now, we only handle "-k" */
-               return 1;
+               return 0;
        }
 
        NrOfServices = LoadServiceCategory(argv[2]);
 
+       DPRINT1("NrOfServices: %lu\n", NrOfServices);
        if (0 == NrOfServices)
-               return 1;
+               return 0;
 
        ServiceTable = HeapAlloc(GetProcessHeap(), 0, sizeof(SERVICE_TABLE_ENTRY) * (NrOfServices + 1));
 
        if (NULL != ServiceTable)
        {
+               DWORD i;
                PSERVICE Service = FirstService;
 
+               /* Fill the service table */
                for (i = 0; i < NrOfServices; ++i)
                {
+                       DPRINT1("Loading service: %s\n", Service->Name);
                        ServiceTable[i].lpServiceName = Service->Name;
                        ServiceTable[i].lpServiceProc = Service->ServiceMainFunc;
                        Service = Service->Next;
                }
 
-               StartServiceCtrlDispatcher(ServiceTable);
+               /* Set a NULL entry to end the service table */
+               ServiceTable[i].lpServiceName = NULL;
+               ServiceTable[i].lpServiceProc = NULL;
+
+               if (FALSE == StartServiceCtrlDispatcher(ServiceTable))
+                       printf("Failed to start service control dispatcher, ErrorCode: %lu\n", GetLastError());
 
                HeapFree(GetProcessHeap(), 0, ServiceTable);
        }
@@ -249,6 +258,7 @@ int _tmain (int argc, LPTSTR argv [])
                DPRINT1("Not enough memory for the service table, trying to allocate %u bytes\n", sizeof(SERVICE_TABLE_ENTRY) * (NrOfServices + 1));
        }
 
+       DPRINT1("Freeing services...\n");
        FreeServices();
 
     return 0;