]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
work in progress
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 24 Aug 2008 19:08:36 +0000 (19:08 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 24 Aug 2008 19:08:36 +0000 (19:08 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10238 e03df62e-2008-0410-955e-edbf42e46eb7

include/win32service.h [new file with mode: 0644]
src/inspircd.cpp
win/configureVC80.vcproj
win/inspircdVC80.vcproj
win/inspircd_win32wrapper.h
win/win32service.cpp

diff --git a/include/win32service.h b/include/win32service.h
new file mode 100644 (file)
index 0000000..93c9c8e
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef _WIN32SERVICE_H_\r
+#define _WIN32SERVICE_H_\r
+
+/* Hook for win32service.cpp to exit properly with the service specific error code */
+#define exit(a) newexit(a)
+void newexit(int status);
+\r
+/* Marks the service as running, not called until the config is parsed */\r
+void SetServiceRunning();\r
+\r
+#endif
\ No newline at end of file
index 0efbd293a4cd8df354e69948f348359af0fc66dc..dab49ddf0cc84a703ab209e5fcf3600da153a4b8 100644 (file)
@@ -719,6 +719,8 @@ InspIRCd::InspIRCd(int argc, char** argv)
                WindowsForkKillOwner(this);
                FreeConsole();
        }
+       /* Set win32 service as running, if we are running as a service */
+       SetServiceRunning();
 #endif
 
        Logs->Log("STARTUP", DEFAULT, "Startup complete as '%s'[%s], %d max open sockets", Config->ServerName,Config->GetSID().c_str(), SE->GetMaxFds());
index 5470916607d2abc81b13de623c94001b40a71070..f9f23ed54754fbac016aba4b6a67e992461eeac4 100644 (file)
@@ -98,9 +98,9 @@
                        />\r
                </Configuration>\r
                <Configuration\r
-                       Name="Debug|x64"\r
+                       Name="Release|Win32"\r
                        OutputDirectory="."\r
-                       IntermediateDirectory="x64Debug_Configure"\r
+                       IntermediateDirectory="Release"\r
                        ConfigurationType="1"\r
                        InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"\r
                        CharacterSet="2"\r
                        />\r
                        <Tool\r
                                Name="VCMIDLTool"\r
-                               TargetEnvironment="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
+                               AdditionalOptions="/I:&quot;include&quot;"\r
                                Optimization="0"\r
-                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;WIN64"\r
+                               WholeProgramOptimization="true"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"\r
                                MinimalRebuild="true"\r
-                               BasicRuntimeChecks="3"\r
-                               RuntimeLibrary="1"\r
+                               RuntimeLibrary="2"\r
                                UsePrecompiledHeader="0"\r
                                WarningLevel="3"\r
-                               Detect64BitPortabilityProblems="true"\r
+                               Detect64BitPortabilityProblems="false"\r
                                DebugInformationFormat="3"\r
                        />\r
                        <Tool\r
                        />\r
                        <Tool\r
                                Name="VCLinkerTool"\r
+                               AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib"\r
                                OutputFile="$(OutDir)/configure.exe"\r
-                               LinkIncremental="2"\r
+                               LinkIncremental="1"\r
                                GenerateDebugInformation="true"\r
-                               ProgramDatabaseFile="$(OutDir)/configure.pdb"\r
                                SubSystem="2"\r
-                               TargetMachine="17"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               LinkTimeCodeGeneration="1"\r
+                               TargetMachine="1"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
                        />\r
                </Configuration>\r
                <Configuration\r
-                       Name="Release|Win32"\r
+                       Name="Debug|x64"\r
                        OutputDirectory="."\r
-                       IntermediateDirectory="Release"\r
+                       IntermediateDirectory="x64Debug_Configure"\r
                        ConfigurationType="1"\r
                        InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"\r
                        CharacterSet="2"\r
                        />\r
                        <Tool\r
                                Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
-                               WholeProgramOptimization="true"\r
-                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;WIN64"\r
                                MinimalRebuild="true"\r
-                               RuntimeLibrary="2"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="1"\r
                                UsePrecompiledHeader="0"\r
                                WarningLevel="3"\r
-                               Detect64BitPortabilityProblems="false"\r
+                               Detect64BitPortabilityProblems="true"\r
                                DebugInformationFormat="3"\r
                        />\r
                        <Tool\r
                        />\r
                        <Tool\r
                                Name="VCLinkerTool"\r
-                               AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib"\r
                                OutputFile="$(OutDir)/configure.exe"\r
-                               LinkIncremental="1"\r
+                               LinkIncremental="2"\r
                                GenerateDebugInformation="true"\r
+                               ProgramDatabaseFile="$(OutDir)/configure.pdb"\r
                                SubSystem="2"\r
-                               OptimizeReferences="2"\r
-                               EnableCOMDATFolding="2"\r
-                               LinkTimeCodeGeneration="1"\r
-                               TargetMachine="1"\r
+                               TargetMachine="17"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
index 263c597ff20f9ef77ac49b4b31a3778238aa747c..aee4dcbde9eb656bc299e1bb41d91d4ec08d1d12 100644 (file)
                                RelativePath="..\include\wildcard.h"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\include\win32service.h"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\include\xline.h"\r
                                >\r
index 94f799c189829a7a8912b7e7dbb2fc4bb12d8ca9..89309fbc92f5a4356cb6209f57ceacfbe28814f8 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef INSPIRCD_WIN32WRAPPER_H
 #define INSPIRCD_WIN32WRAPPER_H
 
+#include "win32service.h"
+
 /* Define the WINDOWS macro. This means we're building on windows to the rest of the server.
    I think this is more reasonable than using WIN32, especially if we're gonna be doing 64-bit compiles */
 #define WINDOWS 1
index 0fb94f3e43370a655f687aae420f16ae141120f3..5923c1458cf2660f9ee0738343710105b0b8fb65 100644 (file)
@@ -40,6 +40,16 @@ struct Commandline
 /* A function pointer for dynamic linking tricks */
 SETSERVDESC ChangeServiceConf;
 
+bool IsAService();
+{
+       USEROBJECTFLAGS uoflags;
+       HWINSTA winstation = GetProcessWindowStation();
+       if (GetUserObjectInformation(winstation, UOI_FLAGS, &uoflags, sizeof(uoflags), NULL))
+               return ((uoflags.dwFlags & WSF_VISIBLE) == 0);
+       else
+               return false;
+}
+
 /* Kills the service by setting an event which the other thread picks up and exits */
 void KillService()
 {
@@ -61,6 +71,22 @@ DWORD WINAPI WorkerThread(LPDWORD param)
        return 0;
 }
 
+/* This is called when all startup is done */
+void SetServiceRunning()
+{
+       if (!IsAService())
+               return;
+
+       serviceCurrentStatus = SERVICE_RUNNING;
+       success = UpdateSCMStatus(SERVICE_RUNNING, NO_ERROR, 0, 0, 0);
+       if (!success)
+       {
+               terminateService(6, GetLastError());
+               return;
+       }
+}
+
+
 /** Starts the worker thread above */
 void StartServiceThread()
 {
@@ -110,10 +136,22 @@ 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)
 {
-       UpdateSCMStatus(SERVICE_STOPPED,wincode?wincode:ERROR_SERVICE_SPECIFIC_ERROR,(wincode)?0:code,0,0);
+       UpdateSCMStatus(SERVICE_STOPPED, wincode ? wincode : ERROR_SERVICE_SPECIFIC_ERROR, wincode ? 0 : code, 0, 0);
        return;
 }
 
+/* In windows we hook this to exit() */
+void newexit(int status)
+{
+       if (!IsAService())
+               exit(status);
+
+       /* Are we running as a service? If so, trigger the service specific exit code */
+       terminateService(status, 0);
+       KillService();
+       exit(status);
+}
+
 /** This callback is called by windows when the state of the service has been changed */
 VOID ServiceCtrlHandler (DWORD controlCode)
 {
@@ -171,13 +209,6 @@ VOID ServiceMain(DWORD argc, LPTSTR *argv)
        }
 
        StartServiceThread();
-       serviceCurrentStatus = SERVICE_RUNNING;
-       success = UpdateSCMStatus(SERVICE_RUNNING, NO_ERROR, 0, 0, 0);
-       if (!success)
-       {
-               terminateService(6, GetLastError());
-               return;
-       }
        WaitForSingleObject (killServiceEvent, INFINITE);
 }
 
@@ -323,13 +354,8 @@ int main(int argc, char** argv)
        /* Check if the process is running interactively. InspIRCd does not run interactively
         * as a service so if this is true, we just run the non-service inspircd.
         */
-       USEROBJECTFLAGS uoflags;
-       HWINSTA winstation = GetProcessWindowStation();
-       if (GetUserObjectInformation(winstation, UOI_FLAGS, &uoflags, sizeof(uoflags), NULL))
-       {
-               if (uoflags.dwFlags == WSF_VISIBLE)
-                       return smain(argc, argv);
-       }
+       if (!IsAService())
+               return smain(argv, argc);
 
        /* If we get here, we know the service is installed so we can start it */