diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-08-23 19:57:02 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-08-23 19:57:02 +0000 |
commit | 443b0f9645d861ca47a6f041a46703e27da7c0c8 (patch) | |
tree | b87e52ce40b681dea0127d4d5375a88d5fad8d8e /src | |
parent | ab7a861a91fd204603775b8d06b1d99c1593229f (diff) |
Raft of fixes so that inspircd can call Cleanup() and Exit() in less 'stable' circumstances, e.g. when half initialized, and it wont segfault.
Also fix OpenLog to not always exit on error, but to return a bool instead, which is much more friendly on rehash (you don't want /REHASH dieing your server if you cant write the log!)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7804 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd_rehash.cpp | 3 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 11 | ||||
-rw-r--r-- | src/inspircd.cpp | 38 | ||||
-rw-r--r-- | src/server.cpp | 3 |
4 files changed, 35 insertions, 20 deletions
diff --git a/src/cmd_rehash.cpp b/src/cmd_rehash.cpp index 34789b0ea..6e214be0a 100644 --- a/src/cmd_rehash.cpp +++ b/src/cmd_rehash.cpp @@ -37,7 +37,8 @@ CmdResult cmd_rehash::Handle (const char** parameters, int pcnt, userrec *user) { ServerInstance->WriteOpers("*** %s is rehashing config file %s",user->nick,ServerConfig::CleanFilename(ServerInstance->ConfigFileName)); ServerInstance->CloseLog(); - ServerInstance->OpenLog(ServerInstance->Config->argv, ServerInstance->Config->argc); + if (!ServerInstance->OpenLog(ServerInstance->Config->argv, ServerInstance->Config->argc)) + user->WriteServ("*** NOTICE %s :ERROR: Could not open logfile %s: %s", user->nick, ServerInstance->Config->logpath.c_str(), strerror(errno)); ServerInstance->RehashUsersAndChans(); FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect()); ServerInstance->Config->Read(false,user); diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 7fba47699..9363e3376 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -31,7 +31,7 @@ static time_t LAST = 0; void InspIRCd::Log(int level, const char* text, ...) { /* sanity check, just in case */ - if (!this->Config) + if (!this->Config || !this->Logger) return; /* Do this check again here so that we save pointless vsnprintf calls */ @@ -51,7 +51,7 @@ void InspIRCd::Log(int level, const char* text, ...) void InspIRCd::Log(int level, const std::string &text) { /* sanity check, just in case */ - if (!this->Config) + if (!this->Config || !this->Logger) return; /* If we were given -debug we output all messages, regardless of configured loglevel */ @@ -442,7 +442,7 @@ bool IsIdentHandler::Call(const char* n) } /* open the proper logfile */ -void InspIRCd::OpenLog(char** argv, int argc) +bool InspIRCd::OpenLog(char** argv, int argc) { Config->MyDir = Config->GetFullProgDir(); @@ -462,11 +462,12 @@ void InspIRCd::OpenLog(char** argv, int argc) if (!Config->log_file) { - printf("ERROR: Could not write to logfile %s: %s\n\n", Config->logpath.c_str(), strerror(errno)); - exit(EXIT_STATUS_LOG); + this->Logger = NULL; + return false; } this->Logger = new FileLogger(this, Config->log_file); + return true; } void InspIRCd::CheckRoot() diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 6d7a26579..4c19878d7 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -77,13 +77,16 @@ void InspIRCd::Cleanup() std::vector<std::string> mymodnames; int MyModCount = this->GetModuleCount(); - for (unsigned int i = 0; i < Config->ports.size(); i++) + if (Config) { - /* This calls the constructor and closes the listening socket */ - delete Config->ports[i]; - } + for (unsigned int i = 0; i < Config->ports.size(); i++) + { + /* This calls the constructor and closes the listening socket */ + delete Config->ports[i]; + } - Config->ports.clear(); + Config->ports.clear(); + } /* Close all client sockets, or the new process inherits them */ for (std::vector<userrec*>::const_iterator i = this->local_users.begin(); i != this->local_users.end(); i++) @@ -101,16 +104,20 @@ void InspIRCd::Cleanup() MyModCount = this->GetModuleCount(); mymodnames.clear(); - /* Unload all modules, so they get a chance to clean up their listeners */ - for (int j = 0; j <= MyModCount; j++) - mymodnames.push_back(Config->module_names[j]); + if (MyModCount) + { + /* Unload all modules, so they get a chance to clean up their listeners */ + for (int j = 0; j <= MyModCount; j++) + mymodnames.push_back(Config->module_names[j]); - for (int k = 0; k <= MyModCount; k++) - this->UnloadModule(mymodnames[k].c_str()); + for (int k = 0; k <= MyModCount; k++) + this->UnloadModule(mymodnames[k].c_str()); + } } /* Close logging */ - this->Logger->Close(); + if (this->Logger) + this->Logger->Close(); /* Cleanup Server Names */ for(servernamelist::iterator itr = servernames.begin(); itr != servernames.end(); ++itr) @@ -183,7 +190,8 @@ void InspIRCd::RehashUsersAndChans() void InspIRCd::CloseLog() { - this->Logger->Close(); + if (this->Logger) + this->Logger->Close(); } void InspIRCd::SetSignals() @@ -411,7 +419,11 @@ InspIRCd::InspIRCd(int argc, char** argv) strlcpy(Config->MyExecutable,argv[0],MAXBUF); - this->OpenLog(argv, argc); + if (!this->OpenLog(argv, argc)) + { + printf("ERROR: Could not open logfile %s: %s\n\n", Config->logpath.c_str(), strerror(errno)); + Exit(EXIT_STATUS_LOG); + } this->stats = new serverstats(); this->Timers = new TimerManager(this); diff --git a/src/server.cpp b/src/server.cpp index f259e4435..b3b02f507 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -46,7 +46,8 @@ void InspIRCd::Rehash() { this->WriteOpers("*** Rehashing config file %s due to SIGHUP",ServerConfig::CleanFilename(this->ConfigFileName)); this->CloseLog(); - this->OpenLog(this->Config->argv, this->Config->argc); + if (!this->OpenLog(this->Config->argv, this->Config->argc)) + this->WriteOpers("*** ERROR: Could not open logfile %s: %s", Config->logpath.c_str(), strerror(errno)); this->RehashUsersAndChans(); FOREACH_MOD_I(this, I_OnGarbageCollect, OnGarbageCollect()); this->Config->Read(false,NULL); |