summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-21 23:46:24 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-21 23:46:24 +0000
commitdcbb0ae938711cd49df73dc2ff6cd6289aeefb44 (patch)
tree82405b49cdba5a0e0f8819df367c75a5c24e455e /src
parentd8f98565a8617658f610bc94a5d87266930beee4 (diff)
Move command-line items to CommandLineConf
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11949 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/configreader.cpp21
-rw-r--r--src/filelogger.cpp7
-rw-r--r--src/helperfuncs.cpp31
-rw-r--r--src/inspircd.cpp56
-rw-r--r--src/logger.cpp34
-rw-r--r--src/xline.cpp3
6 files changed, 51 insertions, 101 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp
index 20e244dcc..9a315fe0b 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -372,16 +372,14 @@ bool ParseStack::ParseExec(const std::string& name, int flags)
ServerConfig::ServerConfig()
{
WhoWasGroupSize = WhoWasMaxGroups = WhoWasMaxKeep = 0;
- log_file = NULL;
- NoUserDns = forcedebug = OperSpyWhois = nofork = HideBans = HideSplits = UndernetMsgPrefix = false;
- CycleHosts = writelog = AllowHalfop = InvBypassModes = true;
+ NoUserDns = OperSpyWhois = HideBans = HideSplits = UndernetMsgPrefix = false;
+ CycleHosts = AllowHalfop = InvBypassModes = true;
dns_timeout = DieDelay = 5;
MaxTargets = 20;
NetBufferSize = 10240;
SoftLimit = ServerInstance->SE->GetMaxFds();
MaxConn = SOMAXCONN;
MaxWhoResults = 0;
- debugging = 0;
MaxChans = 20;
OperMaxChans = 30;
c_ipv4_range = 32;
@@ -668,14 +666,14 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
}
ClassMap newBlocksByMask;
- Classes.resize(config_data.count("type"));
+ Classes.resize(config_data.count("connect"));
std::map<std::string, int> names;
bool try_again = true;
for(int tries=0; try_again; tries++)
{
try_again = false;
- ConfigTagList tags = ConfTags("type");
+ ConfigTagList tags = ConfTags("connect");
int i=0;
for(ConfigIter it = tags.first; it != tags.second; ++it, ++i)
{
@@ -843,8 +841,6 @@ void ServerConfig::Fill()
dns_timeout = ConfValue("dns")->getInt("timeout", 5);
DisabledCommands = ConfValue("disabled")->getString("commands", "");
DisabledDontExist = ConfValue("disabled")->getBool("fakenonexistant");
- SetUser = security->getString("runasuser");
- SetGroup = security->getString("runasgroup");
UserStats = security->getString("userstats");
CustomVersion = security->getString("customversion");
HideSplits = security->getBool("hidesplits");
@@ -992,12 +988,12 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
for (int Index = 0; Index * sizeof(*Once) < sizeof(Once); Index++)
{
std::string tag = Once[Index];
- if (!ConfValue(tag))
- throw CoreException("You have not defined a <"+tag+"> tag, this is required.");
ConfigTagList tags = ConfTags(tag);
+ if (tags.first == tags.second)
+ throw CoreException("You have not defined a <"+tag+"> tag, this is required.");
+ tags.first++;
if (tags.first != tags.second)
{
- tags.first++;
errstr << "You have more than one <" << tag << "> tag.\n"
<< "First occurrence at " << ConfValue(tag)->getTagLocation()
<< "; second occurrence at " << tags.first->second->getTagLocation() << std::endl;
@@ -1034,8 +1030,7 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
{
this->ServerName = old->ServerName;
this->sid = old->sid;
- this->argv = old->argv;
- this->argc = old->argc;
+ this->cmdline = old->cmdline;
// Same for ports... they're bound later on first run.
FailedPortList pl;
diff --git a/src/filelogger.cpp b/src/filelogger.cpp
index f442b8b7a..9e52f1ab5 100644
--- a/src/filelogger.cpp
+++ b/src/filelogger.cpp
@@ -35,12 +35,7 @@ void FileLogStream::OnLog(int loglevel, const std::string &type, const std::stri
static char TIMESTR[26];
static time_t LAST = 0;
- /* sanity check, just in case */
- if (!ServerInstance->Config)
- return;
-
- /* If we were given -debug we output all messages, regardless of configured loglevel */
- if ((loglevel < this->loglvl) && !ServerInstance->Config->forcedebug)
+ if (loglevel < this->loglvl)
{
return;
}
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index eced0c56a..94ba6a037 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -276,36 +276,19 @@ bool IsSIDHandler::Call(const std::string &str)
/* open the proper logfile */
bool InspIRCd::OpenLog(char**, int)
{
- /* This function only happens at startup now */
- if (Config->nofork)
- {
- this->Logs->SetupNoFork();
- }
-
- if (!Config->writelog) return true; // Skip opening default log if -nolog
+ if (!Config->cmdline.writelog) return true; // Skip opening default log if -nolog
- if (!*this->LogFileName)
- {
- if (Config->logpath.empty())
- {
- Config->logpath = "logs/startup.log";
- }
-
- if (!Config->log_file)
- Config->log_file = fopen(Config->logpath.c_str(),"a+");
- }
- else
- {
- Config->log_file = fopen(this->LogFileName,"a+");
- }
+ if (Config->cmdline.startup_log.empty())
+ Config->cmdline.startup_log = "logs/startup.log";
+ FILE* startup = fopen(Config->cmdline.startup_log.c_str(), "a+");
- if (!Config->log_file)
+ if (!startup)
{
return false;
}
- FileWriter* fw = new FileWriter(Config->log_file);
- FileLogStream *f = new FileLogStream((Config->forcedebug ? DEBUG : DEFAULT), fw);
+ FileWriter* fw = new FileWriter(startup);
+ FileLogStream *f = new FileLogStream((Config->cmdline.forcedebug ? DEBUG : DEFAULT), fw);
this->Logs->AddLogType("*", f, true);
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 4404e2323..19f90dd97 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -144,16 +144,16 @@ void InspIRCd::Restart(const std::string &reason)
/* Figure out our filename (if theyve renamed it, we're boned) */
std::string me;
+ char** argv = Config->cmdline.argv;
+
#ifdef WINDOWS
char module[MAX_PATH];
if (GetModuleFileName(NULL, module, MAX_PATH))
me = module;
#else
- me = Config->MyDir + "/inspircd";
+ me = argv[0];
#endif
- char** argv = Config->argv;
-
this->Cleanup();
if (execv(me.c_str(), argv) == -1)
@@ -285,7 +285,7 @@ void InspIRCd::WritePID(const std::string &filename)
}
InspIRCd::InspIRCd(int argc, char** argv) :
- ConfigFileName("inspircd.conf"),
+ ConfigFileName("conf/inspircd.conf"),
/* Functor pointer initialisation.
*
@@ -338,7 +338,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
this->ConfigThread = NULL;
// Initialise TIME
- this->TIME = time(NULL);
+ this->TIME = this->OLDTIME = this->startup_time = time(NULL);
// This must be created first, so other parts of Insp can use it while starting up
this->Logs = new LogManager;
@@ -370,14 +370,11 @@ InspIRCd::InspIRCd(int argc, char** argv) :
this->Parser = new CommandParser;
this->XLines = new XLineManager;
- this->Config->argv = argv;
- this->Config->argc = argc;
+ this->Config->cmdline.argv = argv;
+ this->Config->cmdline.argc = argc;
- this->TIME = this->OLDTIME = this->startup_time = time(NULL);
srand(this->TIME);
- *this->LogFileName = 0;
-
struct option longopts[] =
{
{ "nofork", no_argument, &do_nofork, 1 },
@@ -398,7 +395,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
{
case 'f':
/* Log filename was set */
- strlcpy(LogFileName, optarg, MAXBUF);
+ Config->cmdline.startup_log = optarg;
break;
case 'c':
/* Config filename was set */
@@ -444,14 +441,20 @@ InspIRCd::InspIRCd(int argc, char** argv) :
#endif
/* Set the finished argument values */
- Config->nofork = do_nofork;
- Config->forcedebug = do_debug;
- Config->writelog = !do_nolog;
- Config->TestSuite = do_testsuite;
+ Config->cmdline.nofork = do_nofork;
+ Config->cmdline.forcedebug = do_debug;
+ Config->cmdline.writelog = !do_nolog;
+ Config->cmdline.TestSuite = do_testsuite;
- if (!this->OpenLog(argv, argc))
+ if (do_debug)
+ {
+ FileWriter* fw = new FileWriter(stdout);
+ FileLogStream* fls = new FileLogStream(DEBUG, fw);
+ Logs->AddLogTypes("*", fls, true);
+ }
+ else if (!this->OpenLog(argv, argc))
{
- printf("ERROR: Could not open logfile %s: %s\n\n", Config->logpath.c_str(), strerror(errno));
+ printf("ERROR: Could not open initial logfile %s: %s\n\n", Config->cmdline.startup_log.c_str(), strerror(errno));
Exit(EXIT_STATUS_LOG);
}
@@ -501,7 +504,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
this->SetSignals();
- if (!Config->nofork)
+ if (!Config->cmdline.nofork)
{
if (!this->DaemonSeed())
{
@@ -577,7 +580,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
Config->ServerName.c_str(),Config->GetSID().c_str(), SE->GetMaxFds());
#ifndef WINDOWS
- if (!Config->nofork)
+ if (!Config->cmdline.nofork)
{
if (kill(getppid(), SIGTERM) == -1)
{
@@ -596,7 +599,8 @@ InspIRCd::InspIRCd(int argc, char** argv) :
{
fclose(stdin);
fclose(stderr);
- fclose(stdout);
+ if (!Config->cmdline.forcedebug)
+ fclose(stdout);
}
else
{
@@ -617,7 +621,9 @@ InspIRCd::InspIRCd(int argc, char** argv) :
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
- if (!Config->SetGroup.empty())
+ std::string SetUser = Config->ConfValue("security")->getString("runasuser");
+ std::string SetGroup = Config->ConfValue("security")->getString("runasgroup");
+ if (!SetGroup.empty())
{
int ret;
@@ -634,7 +640,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
struct group *g;
errno = 0;
- g = getgrnam(this->Config->SetGroup.c_str());
+ g = getgrnam(SetGroup.c_str());
if (!g)
{
@@ -651,13 +657,13 @@ InspIRCd::InspIRCd(int argc, char** argv) :
}
}
- if (!Config->SetUser.empty())
+ if (!SetUser.empty())
{
// setuid
struct passwd *u;
errno = 0;
- u = getpwnam(this->Config->SetUser.c_str());
+ u = getpwnam(SetUser.c_str());
if (!u)
{
@@ -681,7 +687,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
int InspIRCd::Run()
{
/* See if we're supposed to be running the test suite rather than entering the mainloop */
- if (Config->TestSuite)
+ if (Config->cmdline.TestSuite)
{
TestSuite* ts = new TestSuite;
delete ts;
diff --git a/src/logger.cpp b/src/logger.cpp
index e92762b46..b265a8ea6 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -44,47 +44,18 @@
LogManager::LogManager()
{
- noforkstream = NULL;
Logging = false;
}
LogManager::~LogManager()
{
- if (noforkstream)
- {
- ServerInstance->Logs = this;
- delete noforkstream;
- ServerInstance->Logs = NULL;
- }
-}
-
-void LogManager::SetupNoFork()
-{
- if (!noforkstream)
- {
- FileWriter* fw = new FileWriter(stdout);
- noforkstream = new FileLogStream(ServerInstance->Config->forcedebug ? DEBUG : DEFAULT, fw);
- }
- else
- {
- noforkstream->ChangeLevel(ServerInstance->Config->forcedebug ? DEBUG : DEFAULT);
- }
- AddLogType("*", noforkstream, false);
}
void LogManager::OpenFileLogs()
{
- /* Re-register the nofork stream if necessary. */
- if (ServerInstance->Config->nofork)
- {
- SetupNoFork();
- }
/* Skip rest of logfile opening if we are running -nolog. */
- if (!ServerInstance->Config->writelog)
- {
+ if (!ServerInstance->Config->cmdline.writelog)
return;
- }
- ConfigReader Conf;
std::map<std::string, FileWriter*> logmap;
ConfigTagList tags = ServerInstance->Config->ConfTags("log");
for(ConfigIter i = tags.first; i != tags.second; ++i)
@@ -98,10 +69,9 @@ void LogManager::OpenFileLogs()
std::string type = tag->getString("type");
std::string level = tag->getString("level");
int loglevel = DEFAULT;
- if (level == "debug" || ServerInstance->Config->forcedebug)
+ if (level == "debug")
{
loglevel = DEBUG;
- ServerInstance->Config->debugging = true;
}
else if (level == "verbose")
{
diff --git a/src/xline.cpp b/src/xline.cpp
index aa43ac43b..51b968a5f 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -494,7 +494,8 @@ XLineManager::~XLineManager()
for(unsigned int i=0; i < sizeof(gekqz); i++)
{
XLineFactory* xlf = GetFactory(std::string(1, gekqz[i]));
- UnregisterFactory(xlf);
+ if (xlf)
+ UnregisterFactory(xlf);
delete xlf;
}