Exemple #1
0
int _tmain (int argc, LPTSTR argv [])
{
	DWORD NrOfServices;
	LPSERVICE_TABLE_ENTRY ServiceTable;

	if (argc < 3)
	{
		/* MS svchost.exe doesn't seem to print help, should we? */
		return 0;
	}

	if (_tcscmp(argv[1], _T("-k")) != 0)
	{
		/* For now, we only handle "-k" */
		return 0;
	}

	NrOfServices = LoadServiceCategory(argv[2]);

	DPRINT("NrOfServices: %lu\n", NrOfServices);
	if (0 == NrOfServices)
		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)
		{
			DPRINT("Loading service: %s\n", Service->Name);
			ServiceTable[i].lpServiceName = Service->Name;
			ServiceTable[i].lpServiceProc = Service->ServiceMainFunc;
			Service = Service->Next;
		}

		/* 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);
	}
	else
	{
		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;
}
Exemple #2
0
void SERVER::FreeAll (void)
{
   if (m_cReqBOS)
      {
      m_cReqBOS = 1;
      CloseBosObject();
      }
   if (m_cReqVOS)
      {
      m_cReqVOS = 1;
      CloseVosObject();
      }

   FreeAggregates();
   FreeServices();
}
Exemple #3
0
BOOL SERVER::RefreshAll (ULONG *pStatus, double dInit, double dFactor)
{
   BOOL rc = TRUE;
   ULONG status = 0;

   if (m_fAggregatesOutOfDate || m_fServicesOutOfDate)
      {
      if ((++cRefreshAllReq) == 1)
         {
         NOTIFYCALLBACK::SendNotificationToAll (evtRefreshAllBegin, GetIdentifier(), 0);
         }

      double perAGGREGATES = 65.0; // % of time spent finding aggs & sets
      double perSERVICES   = 25.0; // % of time spent finding services
      double perVLDB       = 10.0; // % of time spent finding VLDB info

      if (cRefreshAllReq >= 2) // being called as part of a cell-wide op?
         {
         perAGGREGATES = 80.0; // % of time spent finding aggs & sets
         perSERVICES   = 20.0; // % of time spent finding services
         perVLDB       = 0.0;  // we won't query VLDB stuff ourself.
         }

      NOTIFYCALLBACK::SendNotificationToAll (evtRefreshStatusBegin, GetIdentifier());

      if (!CanTalkToServer (&status))  // Determines fCanGetAggregates, fCanGetServices
         {
         if (m_fMonitor)
            SetMonitor (FALSE);
         rc = FALSE;
         }
      else
         {
         if (!m_fCanGetAggregates)
            {
            FreeAggregates();
            m_fAggregatesOutOfDate = FALSE;
            }
         else
            {
            size_t nAggregates = 0;
            size_t iAggregate = 0;
            HENUM hEnum;
            LPAGGREGATE lpAggregate;
            for (lpAggregate = AggregateFindFirst (&hEnum); lpAggregate; lpAggregate = AggregateFindNext (&hEnum))
               {
               ++nAggregates;
               lpAggregate->Close();
               }

            if (nAggregates)
               {
               for (lpAggregate = AggregateFindFirst (&hEnum); lpAggregate; lpAggregate = AggregateFindNext (&hEnum))
                  {
                  ULONG perComplete = (ULONG)( ((double)perAGGREGATES / 100.0) * ((double)iAggregate * 100.0 / nAggregates) );
                  NOTIFYCALLBACK::SendNotificationToAll (evtRefreshAllUpdate, lpAggregate->GetIdentifier(), NULL, NULL, NULL, (ULONG)( 100.0 * dInit + dFactor * (double)perComplete ), 0);

                  lpAggregate->RefreshFilesets (TRUE);
                  lpAggregate->Close();

                  ++iAggregate;
                  }
               }
            }

         if (!m_fCanGetServices)
            {
            FreeServices();
            m_fServicesOutOfDate = FALSE;
            }
         else
            {
            size_t nServices = 0;
            size_t iService = 0;
            HENUM hEnum;
            LPSERVICE lpService;
            for (lpService = ServiceFindFirst (&hEnum); lpService; lpService = ServiceFindNext (&hEnum))
               {
               ++nServices;
               lpService->Close();
               }

            if (nServices)
               {
               for (lpService = ServiceFindFirst (&hEnum); lpService; lpService = ServiceFindNext (&hEnum))
                  {
                  ULONG perComplete = (ULONG)( (double)perAGGREGATES + ((double)perSERVICES / 100.0) * ((double)iService * 100.0 / nServices) );
                  NOTIFYCALLBACK::SendNotificationToAll (evtRefreshAllUpdate, lpService->GetIdentifier(), NULL, NULL, NULL, (ULONG)( 100.0 * dInit + dFactor * (double)perComplete ), 0);

                  lpService->RefreshStatus (TRUE);
                  lpService->Close();

                  ++iService;
                  }
               }
            }

         if (cRefreshAllReq == 1) // not being called as part of a cell-wide op?
            {
            LPCELL lpCell;
            if ((lpCell = OpenCell()) != NULL)
               {
               lpCell->RefreshVLDB (GetIdentifier(), TRUE, NULL);
               lpCell->Close();
               }
            }
         }

      NOTIFYCALLBACK::SendNotificationToAll (evtRefreshStatusEnd, GetIdentifier(), m_lastStatus);

      if ((--cRefreshAllReq) == 0)
         {
         NOTIFYCALLBACK::SendNotificationToAll (evtRefreshAllEnd, GetIdentifier(), NULL, NULL, NULL, 100, m_lastStatus);
         }
      }

   if (rc && m_lastStatus)
      rc = FALSE;
   if (!rc && pStatus)
      *pStatus = status;
   return rc;
}