static SERVICE_STATUS_HANDLE ServiceStatusHandle;
static SERVICE_STATUS ServiceStatus;
+static BOOL bStopService = FALSE;
+
/* FUNCTIONS *****************************************************************/
static VOID
{
ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
ServiceStatus.dwCurrentState = dwState;
- ServiceStatus.dwControlsAccepted = 0;
+
+ if (dwState == SERVICE_PAUSED || dwState == SERVICE_RUNNING)
+ ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP |
+ SERVICE_ACCEPT_SHUTDOWN |
+ SERVICE_ACCEPT_PAUSE_CONTINUE;
+ else
+ ServiceStatus.dwControlsAccepted = 0;
+
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwServiceSpecificExitCode = 0;
ServiceStatus.dwCheckPoint = 0;
switch (dwControl)
{
case SERVICE_CONTROL_STOP:
- TRACE(" SERVICE_CONTROL_STOP received\n");
+ case SERVICE_CONTROL_SHUTDOWN:
+ TRACE(" SERVICE_CONTROL_STOP/SERVICE_CONTROL_SHUTDOWN received\n");
UpdateServiceStatus(SERVICE_STOP_PENDING);
/* Stop listening to incoming RPC messages */
RpcMgmtStopServerListening(NULL);
- UpdateServiceStatus(SERVICE_STOPPED);
+ bStopService = TRUE;
return ERROR_SUCCESS;
case SERVICE_CONTROL_PAUSE:
&ServiceStatus);
return ERROR_SUCCESS;
- case SERVICE_CONTROL_SHUTDOWN:
- TRACE(" SERVICE_CONTROL_SHUTDOWN received\n");
- UpdateServiceStatus(SERVICE_STOP_PENDING);
- RpcMgmtStopServerListening(NULL);
- UpdateServiceStatus(SERVICE_STOPPED);
- return ERROR_SUCCESS;
-
- default :
+ default:
TRACE(" Control %lu received\n", dwControl);
return ERROR_CALL_NOT_IMPLEMENTED;
}
static
DWORD
-ServiceInit(VOID)
+ServiceInit(PHANDLE phEvent)
{
HANDLE hThread;
DWORD dwError;
NULL);
if (!hThread)
{
- ERR("Can't create PortThread\n");
+ ERR("Could not create the RPC thread\n");
return GetLastError();
}
CloseHandle(hThread);
+ /* Create the scheduler event */
+ *phEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ if (*phEvent == NULL)
+ {
+ ERR("Could not create the scheduler event\n");
+ return GetLastError();
+ }
+
return ERROR_SUCCESS;
}
VOID WINAPI
SchedServiceMain(DWORD argc, LPTSTR *argv)
{
+ HANDLE hEvent = NULL;
DWORD dwError;
UNREFERENCED_PARAMETER(argc);
UpdateServiceStatus(SERVICE_START_PENDING);
- dwError = ServiceInit();
+ dwError = ServiceInit(&hEvent);
if (dwError != ERROR_SUCCESS)
{
ERR("Service stopped (dwError: %lu\n", dwError);
}
UpdateServiceStatus(SERVICE_RUNNING);
+
+ for (;;)
+ {
+ /* Leave the loop, if the service has to be stopped */
+ if (bStopService)
+ break;
+
+ /* Wait for the next timeout */
+ WaitForSingleObject(hEvent, 5000);
+ TRACE("Service running!\n");
+ }
+
+ /* Close the scheduler event handle */
+ CloseHandle(hEvent);
+
+ /* Stop the service */
+ UpdateServiceStatus(SERVICE_STOPPED);
}