2008-11-07 12:49:51 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Remote Procedure Call service
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: /base/services/rpcss/service_main.c
|
|
|
|
* PURPOSE: Service control code
|
|
|
|
* COPYRIGHT: Copyright 2008 Ged Murphy <gedmurphy@reactos.org>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "rpcss.h"
|
|
|
|
|
2010-02-22 21:36:07 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
2008-11-07 12:49:51 +00:00
|
|
|
|
2010-02-22 21:36:07 +00:00
|
|
|
extern BOOL RPCSS_Initialize(void);
|
|
|
|
extern BOOL RPCSS_Shutdown(void);
|
|
|
|
extern HANDLE exit_event;
|
2008-11-07 12:49:51 +00:00
|
|
|
|
2010-02-22 21:36:07 +00:00
|
|
|
static VOID WINAPI ServiceMain(DWORD, LPWSTR *);
|
|
|
|
static WCHAR ServiceName[] = L"RpcSs";
|
|
|
|
SERVICE_TABLE_ENTRYW ServiceTable[] =
|
2008-11-07 12:49:51 +00:00
|
|
|
{
|
2010-02-22 21:36:07 +00:00
|
|
|
{ ServiceName, ServiceMain },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static SERVICE_STATUS ServiceStatus;
|
|
|
|
static SERVICE_STATUS_HANDLE ServiceStatusHandle;
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
ServiceControlHandler(DWORD dwControl,
|
|
|
|
DWORD dwEventType,
|
|
|
|
LPVOID lpEventData,
|
|
|
|
LPVOID lpContext)
|
2008-11-07 12:49:51 +00:00
|
|
|
{
|
|
|
|
switch (dwControl)
|
|
|
|
{
|
|
|
|
case SERVICE_CONTROL_SHUTDOWN:
|
|
|
|
case SERVICE_CONTROL_STOP:
|
2010-02-22 21:36:07 +00:00
|
|
|
SetEvent(exit_event);
|
|
|
|
return NO_ERROR;
|
|
|
|
|
|
|
|
case SERVICE_CONTROL_INTERROGATE:
|
|
|
|
return NO_ERROR;
|
2008-11-07 12:49:51 +00:00
|
|
|
|
|
|
|
default:
|
2010-02-22 21:36:07 +00:00
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
2008-11-07 12:49:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID WINAPI
|
|
|
|
ServiceMain(DWORD argc, LPWSTR argv[])
|
|
|
|
{
|
2010-02-22 21:36:07 +00:00
|
|
|
DWORD dwError;
|
|
|
|
|
|
|
|
ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
|
|
|
|
ServiceControlHandler,
|
|
|
|
NULL);
|
|
|
|
if (!ServiceStatusHandle)
|
|
|
|
{
|
|
|
|
dwError = GetLastError();
|
|
|
|
DPRINT1("RegisterServiceCtrlHandlerW() failed! (Error %lu)\n", dwError);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
|
|
|
ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
|
|
|
|
ServiceStatus.dwControlsAccepted = 0;
|
|
|
|
ServiceStatus.dwWin32ExitCode = NO_ERROR;
|
|
|
|
ServiceStatus.dwServiceSpecificExitCode = 0;
|
|
|
|
ServiceStatus.dwCheckPoint = 0;
|
|
|
|
ServiceStatus.dwWaitHint = 1000;
|
|
|
|
SetServiceStatus(ServiceStatusHandle, &ServiceStatus);
|
|
|
|
|
|
|
|
if (RPCSS_Initialize())
|
|
|
|
{
|
|
|
|
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
|
|
|
|
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
|
|
|
|
SetServiceStatus(ServiceStatusHandle, &ServiceStatus);
|
2008-11-07 12:49:51 +00:00
|
|
|
|
2010-02-22 21:36:07 +00:00
|
|
|
WaitForSingleObject(exit_event, INFINITE);
|
2008-11-07 12:49:51 +00:00
|
|
|
|
2010-02-22 21:36:07 +00:00
|
|
|
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
|
|
|
|
SetServiceStatus(ServiceStatusHandle, &ServiceStatus);
|
|
|
|
RPCSS_Shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int wmain(int argc, LPWSTR argv[])
|
2008-11-07 12:49:51 +00:00
|
|
|
{
|
2010-02-22 21:36:07 +00:00
|
|
|
if (!StartServiceCtrlDispatcherW(ServiceTable))
|
2008-11-07 12:49:51 +00:00
|
|
|
{
|
2010-02-22 21:36:07 +00:00
|
|
|
DPRINT1("StartServiceCtrlDispatcherW() failed\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2008-11-07 12:49:51 +00:00
|
|
|
|
2010-02-22 21:36:07 +00:00
|
|
|
return 0;
|
2008-11-07 12:49:51 +00:00
|
|
|
}
|