git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10238
e03df62e-2008-0410-955e-
edbf42e46eb7
--- /dev/null
+#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
WindowsForkKillOwner(this);
FreeConsole();
}
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());
#endif
Logs->Log("STARTUP", DEFAULT, "Startup complete as '%s'[%s], %d max open sockets", Config->ServerName,Config->GetSID().c_str(), SE->GetMaxFds());
/>\r
</Configuration>\r
<Configuration\r
/>\r
</Configuration>\r
<Configuration\r
- IntermediateDirectory="x64Debug_Configure"\r
+ IntermediateDirectory="Release"\r
ConfigurationType="1"\r
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"\r
CharacterSet="2"\r
ConfigurationType="1"\r
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"\r
CharacterSet="2"\r
/>\r
<Tool\r
Name="VCMIDLTool"\r
/>\r
<Tool\r
Name="VCMIDLTool"\r
- TargetEnvironment="3"\r
/>\r
<Tool\r
Name="VCCLCompilerTool"\r
/>\r
<Tool\r
Name="VCCLCompilerTool"\r
+ AdditionalOptions="/I:"include""\r
- PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;WIN64"\r
+ WholeProgramOptimization="true"\r
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"\r
- BasicRuntimeChecks="3"\r
- RuntimeLibrary="1"\r
UsePrecompiledHeader="0"\r
WarningLevel="3"\r
UsePrecompiledHeader="0"\r
WarningLevel="3"\r
- Detect64BitPortabilityProblems="true"\r
+ Detect64BitPortabilityProblems="false"\r
DebugInformationFormat="3"\r
/>\r
<Tool\r
DebugInformationFormat="3"\r
/>\r
<Tool\r
/>\r
<Tool\r
Name="VCLinkerTool"\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
OutputFile="$(OutDir)/configure.exe"\r
GenerateDebugInformation="true"\r
GenerateDebugInformation="true"\r
- ProgramDatabaseFile="$(OutDir)/configure.pdb"\r
+ OptimizeReferences="2"\r
+ EnableCOMDATFolding="2"\r
+ LinkTimeCodeGeneration="1"\r
+ TargetMachine="1"\r
/>\r
<Tool\r
Name="VCALinkTool"\r
/>\r
<Tool\r
Name="VCALinkTool"\r
/>\r
</Configuration>\r
<Configuration\r
/>\r
</Configuration>\r
<Configuration\r
- IntermediateDirectory="Release"\r
+ IntermediateDirectory="x64Debug_Configure"\r
ConfigurationType="1"\r
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"\r
CharacterSet="2"\r
ConfigurationType="1"\r
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"\r
CharacterSet="2"\r
/>\r
<Tool\r
Name="VCMIDLTool"\r
/>\r
<Tool\r
Name="VCMIDLTool"\r
+ TargetEnvironment="3"\r
/>\r
<Tool\r
Name="VCCLCompilerTool"\r
Optimization="0"\r
/>\r
<Tool\r
Name="VCCLCompilerTool"\r
Optimization="0"\r
- WholeProgramOptimization="true"\r
- PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"\r
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;WIN64"\r
+ BasicRuntimeChecks="3"\r
+ RuntimeLibrary="1"\r
UsePrecompiledHeader="0"\r
WarningLevel="3"\r
UsePrecompiledHeader="0"\r
WarningLevel="3"\r
- Detect64BitPortabilityProblems="false"\r
+ Detect64BitPortabilityProblems="true"\r
DebugInformationFormat="3"\r
/>\r
<Tool\r
DebugInformationFormat="3"\r
/>\r
<Tool\r
/>\r
<Tool\r
Name="VCLinkerTool"\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
OutputFile="$(OutDir)/configure.exe"\r
GenerateDebugInformation="true"\r
GenerateDebugInformation="true"\r
+ ProgramDatabaseFile="$(OutDir)/configure.pdb"\r
- OptimizeReferences="2"\r
- EnableCOMDATFolding="2"\r
- LinkTimeCodeGeneration="1"\r
- TargetMachine="1"\r
/>\r
<Tool\r
Name="VCALinkTool"\r
/>\r
<Tool\r
Name="VCALinkTool"\r
RelativePath="..\include\wildcard.h"\r
>\r
</File>\r
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
<File\r
RelativePath="..\include\xline.h"\r
>\r
#ifndef INSPIRCD_WIN32WRAPPER_H
#define INSPIRCD_WIN32WRAPPER_H
#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
/* 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
/* A function pointer for dynamic linking tricks */
SETSERVDESC ChangeServiceConf;
/* 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()
{
/* Kills the service by setting an event which the other thread picks up and exits */
void KillService()
{
+/* 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()
{
/** Starts the worker thread above */
void StartServiceThread()
{
/** 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)
{
/** 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);
+/* 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)
{
/** This callback is called by windows when the state of the service has been changed */
VOID ServiceCtrlHandler (DWORD controlCode)
{
- serviceCurrentStatus = SERVICE_RUNNING;
- success = UpdateSCMStatus(SERVICE_RUNNING, NO_ERROR, 0, 0, 0);
- if (!success)
- {
- terminateService(6, GetLastError());
- return;
- }
WaitForSingleObject (killServiceEvent, INFINITE);
}
WaitForSingleObject (killServiceEvent, INFINITE);
}
/* 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.
*/
/* 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 */
/* If we get here, we know the service is installed so we can start it */