summaryrefslogtreecommitdiff
path: root/src/inspircd.cpp
diff options
context:
space:
mode:
authorChrisTX <chris@rev-crew.info>2012-10-12 22:31:38 +0200
committerChrisTX <chris@rev-crew.info>2012-10-12 22:31:38 +0200
commit5b9682275e384635a1fd9f7320cf4d9a604a43b4 (patch)
tree8cd47480717046cbf0fa9beeb3ef0fe65e193ec5 /src/inspircd.cpp
parent152bf4946c3cdee3e8b66cb2babbf3182840d054 (diff)
Windows: In-depth cleanup (see details)
-Fix x64 builds for Windows. Now all configurations compile. -Remove the non-working rebase stuff. -Remove the Windows fork hack and instead use FreeConsole() to emulate the behavior. This directly allows us to compile with ASLR, which is turned on now. -Remove the old IPC mechanism for the removed GUI. This is not needed anymore as the GUI wasn't ever supported on anything newer than 1.2 -Remove the WIN32/WINDOWS macros. _WIN32 is supported on all x86-based VC++ targets, so that's what we need. -Enable optimizations for release builds. -De-duplicate printf_c(), it was previously copy-pasted into colors.h for configure -Add the VC++ specific bad files in .gitignore -Disable PID writing on Windows. This is only making sense for *nix builds. -Replace the CPU usage retrieval with an algorithm analogous to the *nix behavior. Also supports separated now/total values. (Tested with a dummy busy loop - seems working) -Removed certain unused functions and variables -Remove stdint defines from the windows wrapper -Remove CRT debug alloc. This is a bad idea as it would define a macro to replace free which breaks builds. -Re-evaluated the warnings list, commented it. -Moved inspircd_config/_version to include/ to match *nix -Removed the creation of inspircd_se_config, as it isn't used at all. -Made non-git builds show as "r0" instead of "r" (thanks to @SaberUK for pointing this out) -Fixed up m_spanningtree's project paths. Now all configurations (debug/release x86/x64) have been tested and build properly. -Moved FindDNS out of the wrapper and matched its log behavior with *nix. (It's pointless having it in the wrapper after the recent slimming down) -Replaced random/srandom wrappers with a mechanism that tries to use Windows' Random API first is no SSL module is loaded. -Removed more old junk from support for compilers older than VC++ 2010 (we don't have project files for these, so compiling them would be hard anyways) -Removed the unused ClearConsole() -Removed unused includes from the wrapper. Also, do not include psapi.h here if we don't link psapi.lib. This should be done where appropriate. -Made inet_aton an inline function for increased performance -C4800, performance warning about bool forcing, resolved at all occurrences. -C4701, uninitialized variable 'cached', resolved at all occurrences. -dlerror() was migrated out of the wrapper for more thread safety (no global buffer being shared) and increased performance. -Removed the wrong CRT debug flags. This drains a lot of performance. -Removed the clock_gettime/gettimeofday wrappers -Replaced all TCHAR/ANSI mix-ups of functions with the correct respective function. -Added a block of C4355 for < VS2012 -Update project files for c870714
Diffstat (limited to 'src/inspircd.cpp')
-rw-r--r--src/inspircd.cpp107
1 files changed, 56 insertions, 51 deletions
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index d154c3600..42047ce11 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -31,7 +31,7 @@
#include "inspircd_version.h"
#include <signal.h>
-#ifndef WIN32
+#ifndef _WIN32
#include <dirent.h>
#include <unistd.h>
#include <sys/resource.h>
@@ -163,9 +163,9 @@ void InspIRCd::Restart(const std::string &reason)
char** argv = Config->cmdline.argv;
-#ifdef WINDOWS
+#ifdef _WIN32
char module[MAX_PATH];
- if (GetModuleFileName(NULL, module, MAX_PATH))
+ if (GetModuleFileNameA(NULL, module, MAX_PATH))
me = module;
#else
me = argv[0];
@@ -223,7 +223,7 @@ void InspIRCd::RehashUsersAndChans()
void InspIRCd::SetSignals()
{
-#ifndef WIN32
+#ifndef _WIN32
signal(SIGALRM, SIG_IGN);
signal(SIGHUP, InspIRCd::SetSignal);
signal(SIGPIPE, SIG_IGN);
@@ -241,7 +241,7 @@ void InspIRCd::QuickExit(int status)
bool InspIRCd::DaemonSeed()
{
-#ifdef WINDOWS
+#ifdef _WIN32
printf_c("InspIRCd Process ID: \033[1;32m%lu\033[0m\n", GetCurrentProcessId());
return true;
#else
@@ -285,6 +285,7 @@ bool InspIRCd::DaemonSeed()
void InspIRCd::WritePID(const std::string &filename)
{
+#ifndef _WIN32
std::string fname(filename);
if (fname.empty())
fname = DATA_PATH "/inspircd.pid";
@@ -300,6 +301,7 @@ void InspIRCd::WritePID(const std::string &filename)
this->Logs->Log("STARTUP",DEFAULT,"Failed to write PID-file '%s', exiting.",fname.c_str());
Exit(EXIT_STATUS_PID);
}
+#endif
}
InspIRCd::InspIRCd(int argc, char** argv) :
@@ -321,14 +323,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
FloodQuitUser(&HandleFloodQuitUser),
OnCheckExemption(&HandleOnCheckExemption)
{
-#ifdef WIN32
- // Strict, frequent checking of memory on debug builds
- _CrtSetDbgFlag ( _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
-
- // Avoid erroneous frees on early exit
- WindowsIPC = 0;
-#endif
-
ServerInstance = this;
Extensions.Register(&NICKForced);
@@ -393,7 +387,11 @@ InspIRCd::InspIRCd(int argc, char** argv) :
this->Config->cmdline.argv = argv;
this->Config->cmdline.argc = argc;
+#ifdef _WIN32
+ srand(TIME.tv_nsec ^ TIME.tv_sec);
+#else
srandom(TIME.tv_nsec ^ TIME.tv_sec);
+#endif
struct option longopts[] =
{
@@ -444,27 +442,17 @@ InspIRCd::InspIRCd(int argc, char** argv) :
Exit(EXIT_STATUS_NOERROR);
}
-#ifdef WIN32
-
- // Handle forking
- if(!do_nofork)
- {
- DWORD ExitCode = WindowsForkStart();
- if(ExitCode)
- exit(ExitCode);
- }
-
+#ifdef _WIN32
// Set up winsock
WSADATA wsadata;
- WSAStartup(MAKEWORD(2,0), &wsadata);
- ChangeWindowsSpecificPointers();
+ WSAStartup(MAKEWORD(2,2), &wsadata);
#endif
/* Set the finished argument values */
- Config->cmdline.nofork = do_nofork;
- Config->cmdline.forcedebug = do_debug;
- Config->cmdline.writelog = !do_nolog;
- Config->cmdline.TestSuite = do_testsuite;
+ Config->cmdline.nofork = (do_nofork != 0);
+ Config->cmdline.forcedebug = (do_debug != 0);
+ Config->cmdline.writelog = (!do_nolog != 0);
+ Config->cmdline.TestSuite = (do_testsuite != 0);
if (do_debug)
{
@@ -480,7 +468,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
if (!ServerConfig::FileExists(ConfigFileName.c_str()))
{
-#ifdef WIN32
+#ifdef _WIN32
/* Windows can (and defaults to) hide file extensions, so let's play a bit nice for windows users. */
std::string txtconf = this->ConfigFileName;
txtconf.append(".txt");
@@ -507,6 +495,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
this->Modes = new ModeParser;
+#ifndef _WIN32
if (!do_root)
this->CheckRoot();
else
@@ -521,6 +510,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
printf("\nInspIRCd starting in 20 seconds, ctrl+c to abort...\n");
sleep(20);
}
+#endif
this->SetSignals();
@@ -598,7 +588,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
printf("\nInspIRCd is now running as '%s'[%s] with %d max open sockets\n",
Config->ServerName.c_str(),Config->GetSID().c_str(), SE->GetMaxFds());
-#ifndef WINDOWS
+#ifndef _WIN32
if (!Config->cmdline.nofork)
{
if (kill(getppid(), SIGTERM) == -1)
@@ -640,19 +630,21 @@ InspIRCd::InspIRCd(int argc, char** argv) :
Logs->Log("STARTUP", DEFAULT,"Keeping pseudo-tty open as we are running in the foreground.");
}
#else
- WindowsIPC = new IPC;
- if(!Config->cmdline.nofork)
+ /* Set win32 service as running, if we are running as a service */
+ SetServiceRunning();
+
+ // Handle forking
+ if(!do_nofork)
{
- WindowsForkKillOwner();
FreeConsole();
}
- /* Set win32 service as running, if we are running as a service */
- SetServiceRunning();
+
+ QueryPerformanceFrequency(&stats->QPFrequency);
#endif
Logs->Log("STARTUP", DEFAULT, "Startup complete as '%s'[%s], %d max open sockets", Config->ServerName.c_str(),Config->GetSID().c_str(), SE->GetMaxFds());
-#ifndef WIN32
+#ifndef _WIN32
std::string SetUser = Config->ConfValue("security")->getString("runasuser");
std::string SetGroup = Config->ConfValue("security")->getString("runasgroup");
if (!SetGroup.empty())
@@ -711,20 +703,28 @@ InspIRCd::InspIRCd(int argc, char** argv) :
this->QuickExit(0);
}
}
-#endif
this->WritePID(Config->PID);
+#endif
}
void InspIRCd::UpdateTime()
{
-#ifdef HAS_CLOCK_GETTIME
- clock_gettime(CLOCK_REALTIME, &TIME);
+#ifdef _WIN32
+ SYSTEMTIME st;
+ GetSystemTime(&st);
+
+ TIME.tv_sec = time(NULL);
+ TIME.tv_nsec = st.wMilliseconds;
#else
- struct timeval tv;
- gettimeofday(&tv, NULL);
- TIME.tv_sec = tv.tv_sec;
- TIME.tv_nsec = tv.tv_usec * 1000;
+ #ifdef HAS_CLOCK_GETTIME
+ clock_gettime(CLOCK_REALTIME, &TIME);
+ #else
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ TIME.tv_sec = tv.tv_sec;
+ TIME.tv_nsec = tv.tv_usec * 1000;
+ #endif
#endif
}
@@ -743,12 +743,8 @@ int InspIRCd::Run()
while (true)
{
-#ifndef WIN32
+#ifndef _WIN32
static rusage ru;
-#else
- static time_t uptime;
- static struct tm * stime;
- static char window_title[100];
#endif
/* Check if there is a config thread which has finished executing but has not yet been freed */
@@ -774,12 +770,21 @@ int InspIRCd::Run()
if (TIME.tv_sec != OLDTIME)
{
OLDTIME = TIME.tv_sec;
-#ifndef WIN32
+#ifndef _WIN32
getrusage(RUSAGE_SELF, &ru);
stats->LastSampled = TIME;
stats->LastCPU = ru.ru_utime;
#else
- WindowsIPC->Check();
+ if(QueryPerformanceCounter(&stats->LastSampled))
+ {
+ FILETIME CreationTime;
+ FILETIME ExitTime;
+ FILETIME KernelTime;
+ FILETIME UserTime;
+ GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime);
+ stats->LastCPU.dwHighDateTime = KernelTime.dwHighDateTime + UserTime.dwHighDateTime;
+ stats->LastCPU.dwLowDateTime = KernelTime.dwLowDateTime + UserTime.dwLowDateTime;
+ }
#endif
/* Allow a buffer of two seconds drift on this so that ntpdate etc dont harass admins */