#include <stdio.h>\r
\r
extern int smain(int argc, char** argv);\r
+extern const char* dlerror();\r
\r
static SERVICE_STATUS_HANDLE serviceStatusHandle;\r
static HANDLE hThreadEvent;\r
// This is used to define ChangeServiceConf2() as we can't link\r
// directly against this symbol (see below where it is used)\r
typedef BOOL (CALLBACK* SETSERVDESC)(SC_HANDLE,DWORD,LPVOID);\r
+typedef void (*CommandlineParameterHandler)(void);\r
\r
SETSERVDESC ChangeServiceConf; // A function pointer for dynamic linking tricks\r
\r
serviceStatusHandle = RegisterServiceCtrlHandler("InspIRCd", (LPHANDLER_FUNCTION)ServiceCtrlHandler);\r
if (!serviceStatusHandle)\r
{\r
- terminateService(1,GetLastError());\r
+ terminateService(1, GetLastError());\r
return;\r
}\r
\r
success = UpdateSCMStatus(SERVICE_START_PENDING, NO_ERROR, 0, 1, 1000);\r
if (!success)\r
{\r
- terminateService(2,GetLastError());\r
+ terminateService(2, GetLastError());\r
return;\r
}\r
\r
\r
if (!killServiceEvent || !hThreadEvent)\r
{\r
- terminateService(99,GetLastError());\r
+ terminateService(99, GetLastError());\r
return;\r
}\r
\r
success = UpdateSCMStatus(SERVICE_START_PENDING, NO_ERROR, 0, 2, 1000);\r
if (!success)\r
{\r
- terminateService(2,GetLastError());\r
+ terminateService(2, GetLastError());\r
return;\r
}\r
\r
success = UpdateSCMStatus(SERVICE_RUNNING, NO_ERROR, 0, 0, 0);\r
if (!success)\r
{\r
- terminateService(6,GetLastError());\r
+ terminateService(6, GetLastError());\r
return;\r
}\r
WaitForSingleObject (killServiceEvent, INFINITE);\r
}\r
\r
-void InstallService(void)\r
+void InstallService()\r
{\r
SC_HANDLE myService, scm;\r
SERVICE_DESCRIPTION svDesc;\r
scm = OpenSCManager(0,0,SC_MANAGER_CREATE_SERVICE);\r
if (!scm)\r
{\r
- printf("Unable to open service control manager: %d\n", GetLastError());\r
+ printf("Unable to open service control manager: %s\n", dlerror());\r
return;\r
}\r
\r
\r
if (!myService)\r
{\r
- printf("Unable to create service: %d\n", GetLastError());\r
+ printf("Unable to create service: %s\n", dlerror());\r
CloseServiceHandle(scm);\r
return;\r
}\r
ChangeServiceConf = (SETSERVDESC)GetProcAddress(advapi32,"ChangeServiceConfig2A");\r
if (ChangeServiceConf)\r
{\r
- char desc[] = "The Inspire Internet Relay Chat Daemon hosts IRC channels and conversations. \\r
- If this service is stopped, the IRC server will not run.";\r
+ char desc[] = "The Inspire Internet Relay Chat Daemon hosts IRC channels and conversations.\\r
+ If this service is stopped, the IRC server will not run.";\r
svDesc.lpDescription = desc;\r
BOOL success = ChangeServiceConf(myService,SERVICE_CONFIG_DESCRIPTION, &svDesc);\r
if (!success)\r
{\r
- printf("Unable to set service description: %d\n", GetLastError());\r
+ printf("Unable to set service description: %s\n", dlerror());\r
CloseServiceHandle(myService);\r
CloseServiceHandle(scm);\r
return;\r
CloseServiceHandle(scm);\r
}\r
\r
-void RemoveService(void)\r
+void RemoveService()\r
{\r
SC_HANDLE myService, scm;\r
\r
scm = OpenSCManager(0,0,SC_MANAGER_CREATE_SERVICE);\r
if (!scm)\r
{\r
- printf("Unable to open service control manager: %d\n", GetLastError());\r
+ printf("Unable to open service control manager: %s\n", dlerror());\r
return;\r
}\r
\r
myService = OpenService(scm,"InspIRCd",SERVICE_ALL_ACCESS);\r
if (!myService)\r
{\r
- printf("Unable to open service: %d\n", GetLastError());\r
+ printf("Unable to open service: %s\n", dlerror());\r
CloseServiceHandle(scm);\r
return;\r
}\r
\r
if (!DeleteService(myService))\r
{\r
- printf("Unable to delete service: %d\n", GetLastError());\r
+ printf("Unable to delete service: %s\n", dlerror());\r
CloseServiceHandle(myService);\r
CloseServiceHandle(scm);\r
return;\r
CloseServiceHandle(scm);\r
}\r
\r
+struct Commandline\r
+{\r
+ const char* Switch;\r
+ CommandlineParameterHandler Handler;\r
+};\r
+\r
/* In windows, our main() flows through here, before calling the 'real' main, smain() in inspircd.cpp */\r
int main(int argc, char** argv)\r
{\r
+\r
+ Commandline params[] = {\r
+ { "--installservice", InstallService },\r
+ { "--removeservice", RemoveService },\r
+ { NULL }\r
+ };\r
+\r
/* Check for parameters */\r
if (argc > 1)\r
{\r
- if (!_stricmp(argv[1], "--installservice"))\r
+ for (int z = 0; params[z].Switch; ++z)\r
{\r
- InstallService();\r
- return 0;\r
- }\r
- else if (!_stricmp(argv[1], "--removeservice"))\r
- {\r
- RemoveService();\r
- return 0;\r
+ if (!_stricmp(argv[1], params[z].Switch))\r
+ {\r
+ params[z].Handler();\r
+ return 0;\r
+ }\r
}\r
}\r
\r