summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/configreader.h113
-rw-r--r--include/inspircd.h4
-rw-r--r--include/logger.h10
-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
9 files changed, 99 insertions, 180 deletions
diff --git a/include/configreader.h b/include/configreader.h
index 024e28909..b0985f1b5 100644
--- a/include/configreader.h
+++ b/include/configreader.h
@@ -110,6 +110,49 @@ class ServerLimits
}
};
+struct CommandLineConf
+{
+ /** If this value is true, the owner of the
+ * server specified -nofork on the command
+ * line, causing the daemon to stay in the
+ * foreground.
+ */
+ bool nofork;
+
+ /** If this value if true then all log
+ * messages will be output, regardless of
+ * the level given in the config file.
+ * This is set with the -debug commandline
+ * option.
+ */
+ bool forcedebug;
+
+ /** If this is true then log output will be
+ * written to the logfile. This is the default.
+ * If you put -nolog on the commandline then
+ * the logfile will not be written.
+ * This is meant to be used in conjunction with
+ * -debug for debugging without filling up the
+ * hard disk.
+ */
+ bool writelog;
+
+ /** True if we have been told to run the testsuite from the commandline,
+ * rather than entering the mainloop.
+ */
+ bool TestSuite;
+
+ /** Saved argc from startup
+ */
+ int argc;
+
+ /** Saved argv from startup
+ */
+ char** argv;
+
+ std::string startup_log;
+};
+
class CoreExport OperInfo : public refcountbase
{
public:
@@ -186,6 +229,10 @@ class CoreExport ServerConfig
*/
ServerLimits Limits;
+ /** Configuration parsed from the command line.
+ */
+ CommandLineConf cmdline;
+
/** Clones CIDR range for ipv4 (0-32)
* Defaults to 32 (checks clones on all IPs seperately)
*/
@@ -209,11 +256,6 @@ class CoreExport ServerConfig
*/
int WhoWasMaxKeep;
- /** Both for set(g|u)id.
- */
- std::string SetUser;
- std::string SetGroup;
-
/** Holds the server name of the local server
* as defined by the administrator.
*/
@@ -316,7 +358,6 @@ class CoreExport ServerConfig
/** This variable identifies which usermodes have been diabled.
*/
-
char DisabledUModes[64];
/** This variable identifies which chanmodes have been disabled.
@@ -326,43 +367,10 @@ class CoreExport ServerConfig
/** The full path to the modules directory.
* This is either set at compile time, or
* overridden in the configuration file via
- * the <options> tag.
+ * the <path> tag.
*/
std::string ModPath;
- /** The file handle of the logfile. If this
- * value is NULL, the log file is not open,
- * probably due to a permissions error on
- * startup (this should not happen in normal
- * operation!).
- */
- FILE *log_file;
-
- /** If this value is true, the owner of the
- * server specified -nofork on the command
- * line, causing the daemon to stay in the
- * foreground.
- */
- bool nofork;
-
- /** If this value if true then all log
- * messages will be output, regardless of
- * the level given in the config file.
- * This is set with the -debug commandline
- * option.
- */
- bool forcedebug;
-
- /** If this is true then log output will be
- * written to the logfile. This is the default.
- * If you put -nolog on the commandline then
- * the logfile will not be written.
- * This is meant to be used in conjunction with
- * -debug for debugging without filling up the
- * hard disk.
- */
- bool writelog;
-
/** If set to true, then all opers on this server are
* shown with a generic 'is an IRC operator' line rather
* than the oper type. Oper types are still used internally.
@@ -417,10 +425,6 @@ class CoreExport ServerConfig
*/
int MaxWhoResults;
- /** True if the DEBUG loglevel is selected.
- */
- int debugging;
-
/** How many seconds to wait before exiting
* the program when /DIE is correctly issued.
*/
@@ -484,10 +488,6 @@ class CoreExport ServerConfig
*/
std::string UserStats;
- /** The path and filename of the ircd.log file
- */
- std::string logpath;
-
/** Default channel modes
*/
std::string DefaultModes;
@@ -504,10 +504,6 @@ class CoreExport ServerConfig
*/
std::map<std::string, int> maxbans;
- /** Directory where the inspircd binary resides
- */
- std::string MyDir;
-
/** If set to true, no user DNS lookups are to be performed
*/
bool NoUserDns;
@@ -536,14 +532,6 @@ class CoreExport ServerConfig
*/
OperIndex oper_blocks;
- /** Saved argv from startup
- */
- char** argv;
-
- /** Saved argc from startup
- */
- int argc;
-
/** Max channels per user
*/
unsigned int MaxChans;
@@ -559,11 +547,6 @@ class CoreExport ServerConfig
*/
std::string sid;
- /** True if we have been told to run the testsuite from the commandline,
- * rather than entering the mainloop.
- */
- bool TestSuite;
-
/** Construct a new ServerConfig
*/
ServerConfig();
diff --git a/include/inspircd.h b/include/inspircd.h
index e79a56f53..ab815dd10 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -315,10 +315,6 @@ class CoreExport InspIRCd
*/
bool AllModulesReportReady(LocalUser* user);
- /** Logfile pathname specified on the commandline, or empty string
- */
- char LogFileName[MAXBUF];
-
/** The current time, updated in the mainloop
*/
time_t TIME;
diff --git a/include/logger.h b/include/logger.h
index f0cbe14d3..ca96ac242 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -112,10 +112,6 @@ class CoreExport LogManager
*/
bool Logging;
- /** LogStream for -nofork, logs to STDOUT when it's active.
- */
- LogStream* noforkstream;
-
/** Map of active log types and what LogStreams will receive them.
*/
std::map<std::string, std::vector<LogStream *> > LogStreams;
@@ -138,12 +134,6 @@ class CoreExport LogManager
LogManager();
~LogManager();
- /** Sets up the logstream for -nofork. Called by InspIRCd::OpenLog() and LogManager::OpenFileLogs().
- * First time called it creates the nofork stream and stores it in noforkstream. Each call thereafter just readds it to GlobalLogStreams
- * and updates the loglevel.
- */
- void SetupNoFork();
-
/** Adds a FileWriter instance to LogManager, or increments the reference count of an existing instance.
* Used for file-stream sharing for FileLogStreams.
*/
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;
}