]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
add text explanations of the error messages that can occur when adding or removing...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 21 Aug 2008 12:39:21 +0000 (12:39 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 21 Aug 2008 12:39:21 +0000 (12:39 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10197 e03df62e-2008-0410-955e-edbf42e46eb7

win/win32service.cpp

index b6bca46b22a35a3478d0deec1dd6b962f4c93578..ca44019c05205c9c42973630962259d7ce368cd0 100644 (file)
@@ -17,6 +17,7 @@
 #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
@@ -26,6 +27,7 @@ static int serviceCurrentStatus;
 // 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
@@ -128,14 +130,14 @@ VOID ServiceMain(DWORD argc, LPTSTR *argv)
        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
@@ -144,14 +146,14 @@ VOID ServiceMain(DWORD argc, LPTSTR *argv)
 \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
@@ -160,13 +162,13 @@ VOID ServiceMain(DWORD argc, LPTSTR *argv)
        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
@@ -178,7 +180,7 @@ void InstallService(void)
        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
@@ -187,7 +189,7 @@ void InstallService(void)
 \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
@@ -202,13 +204,13 @@ void InstallService(void)
                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
@@ -222,28 +224,28 @@ void InstallService(void)
        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
@@ -254,21 +256,32 @@ void RemoveService(void)
        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