X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=win%2Fwin32service.cpp;h=59a06b7097dd6ebf2af7bd664137b42fafce1379;hb=819147178db00008a215670992d0f532dd57f9e5;hp=42eaa998b4b16061be4b5dc262f3f689f41af852;hpb=a539875eccf01c6d0a5fb21649d10a23ad191b23;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/win/win32service.cpp b/win/win32service.cpp index 42eaa998b..59a06b709 100644 --- a/win/win32service.cpp +++ b/win/win32service.cpp @@ -2,8 +2,8 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2008 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see * the file COPYING for details. @@ -12,6 +12,7 @@ */ #include "inspircd_config.h" #include "inspircd.h" +#include "exitcodes.h" #include #include #include @@ -27,8 +28,8 @@ static int serviceCurrentStatus; */ typedef BOOL (CALLBACK* SETSERVDESC)(SC_HANDLE,DWORD,LPVOID); -BOOL UpdateSCMStatus (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint); -void terminateService (int code, int wincode); +BOOL UpdateSCMStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint); +void terminateService(int code, int wincode); /* A commandline parameter handler for service specific commandline parameters */ typedef void (*CommandlineParameterHandler)(void); @@ -43,6 +44,7 @@ struct Commandline /* A function pointer for dynamic linking tricks */ SETSERVDESC ChangeServiceConf; +/* Returns true if this program is running as a service, false if it is running interactive */ bool IsAService() { USEROBJECTFLAGS uoflags; @@ -68,8 +70,8 @@ DWORD WINAPI WorkerThread(LPDWORD param) { char modname[MAX_PATH]; GetModuleFileName(NULL, modname, sizeof(modname)); - char* argv[] = { modname, "--nofork", "--debug" }; - smain(3, argv); + char* argv[] = { modname, "--nofork" }; + smain(2, argv); KillService(); return 0; } @@ -84,7 +86,7 @@ void SetServiceRunning() BOOL success = UpdateSCMStatus(SERVICE_RUNNING, NO_ERROR, 0, 0, 0); if (!success) { - terminateService(6, GetLastError()); + terminateService(EXIT_STATUS_UPDATESCM_FAILED, GetLastError()); return; } } @@ -100,7 +102,7 @@ void StartServiceThread() /** This function updates the status of the service in the SCM * (service control manager, the services.msc applet) */ -BOOL UpdateSCMStatus (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint) +BOOL UpdateSCMStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint) { BOOL success; SERVICE_STATUS serviceStatus; @@ -137,13 +139,13 @@ BOOL UpdateSCMStatus (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServi } /** This function is called by us when the service is being shut down or when it can't be started */ -void terminateService (int code, int wincode) +void terminateService(int code, int wincode) { UpdateSCMStatus(SERVICE_STOPPED, wincode ? wincode : ERROR_SERVICE_SPECIFIC_ERROR, wincode ? 0 : code, 0, 0); return; } -/* In windows we hook this to exit() */ +/* In windows we hook this to InspIRCd::Exit() */ void SetServiceStopped(int status) { if (!IsAService()) @@ -156,7 +158,7 @@ void SetServiceStopped(int status) } /** This callback is called by windows when the state of the service has been changed */ -VOID ServiceCtrlHandler (DWORD controlCode) +VOID ServiceCtrlHandler(DWORD controlCode) { switch(controlCode) { @@ -179,19 +181,18 @@ VOID ServiceCtrlHandler (DWORD controlCode) VOID ServiceMain(DWORD argc, LPTSTR *argv) { BOOL success; - DWORD type=0, size=0; serviceStatusHandle = RegisterServiceCtrlHandler("InspIRCd", (LPHANDLER_FUNCTION)ServiceCtrlHandler); if (!serviceStatusHandle) { - terminateService(1, GetLastError()); + terminateService(EXIT_STATUS_RSCH_FAILED, GetLastError()); return; } success = UpdateSCMStatus(SERVICE_START_PENDING, NO_ERROR, 0, 1, 1000); if (!success) { - terminateService(2, GetLastError()); + terminateService(EXIT_STATUS_UPDATESCM_FAILED, GetLastError()); return; } @@ -200,14 +201,14 @@ VOID ServiceMain(DWORD argc, LPTSTR *argv) if (!killServiceEvent || !hThreadEvent) { - terminateService(99, GetLastError()); + terminateService(EXIT_STATUS_CREATE_EVENT_FAILED, GetLastError()); return; } success = UpdateSCMStatus(SERVICE_START_PENDING, NO_ERROR, 0, 2, 1000); if (!success) { - terminateService(2, GetLastError()); + terminateService(EXIT_STATUS_UPDATESCM_FAILED, GetLastError()); return; }