X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Finspircd.cpp;h=12962d92d6391dcd8b3033477adbe22f58ce2547;hb=f1f8173bb5ca5f5ce01ad92d0ccd309f232fc138;hp=48746cb527498b338de692eaf4abb672f9f71340;hpb=54d10d53c730ab81ca6464fe2f0e0ecbcd435672;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 48746cb52..12962d92d 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -107,12 +107,9 @@ void InspIRCd::Cleanup() ports.clear(); /* Close all client sockets, or the new process inherits them */ - LocalUserList::reverse_iterator i = Users->local_users.rbegin(); - while (i != this->Users->local_users.rend()) - { - User* u = *i++; - Users->QuitUser(u, "Server shutdown"); - } + LocalUserList& list = Users->local_users; + for (LocalUserList::iterator i = list.begin(); i != list.end(); ++i) + Users->QuitUser(*i, "Server shutdown"); GlobalCulls.Apply(); Modules->UnloadAll(); @@ -120,7 +117,10 @@ void InspIRCd::Cleanup() /* Delete objects dynamically allocated in constructor (destructor would be more appropriate, but we're likely exiting) */ /* Must be deleted before modes as it decrements modelines */ if (FakeClient) + { + delete FakeClient->server; FakeClient->cull(); + } DeleteZero(this->FakeClient); DeleteZero(this->Users); DeleteZero(this->Modes); @@ -154,6 +154,12 @@ void InspIRCd::SetSignals() } void InspIRCd::QuickExit(int status) +{ + exit(status); +} + +// Required for returning the proper value of EXIT_SUCCESS for the parent process +static void VoidSignalHandler(int signalreceived) { exit(0); } @@ -164,7 +170,8 @@ bool InspIRCd::DaemonSeed() std::cout << "InspIRCd Process ID: " << con_green << GetCurrentProcessId() << con_reset << std::endl; return true; #else - signal(SIGTERM, InspIRCd::QuickExit); + // Do not use QuickExit here: It will exit with status SIGTERM which would break e.g. daemon scripts + signal(SIGTERM, VoidSignalHandler); int childpid = fork(); if (childpid < 0) @@ -207,7 +214,7 @@ void InspIRCd::WritePID(const std::string &filename) #ifndef _WIN32 std::string fname(filename); if (fname.empty()) - fname = DATA_PATH "/inspircd.pid"; + fname = ServerInstance->Config->Paths.PrependData("inspircd.pid"); std::ofstream outfile(fname.c_str()); if (outfile.is_open()) { @@ -231,10 +238,9 @@ InspIRCd::InspIRCd(int argc, char** argv) : * THIS MUST MATCH THE ORDER OF DECLARATION OF THE FUNCTORS, e.g. the methods * themselves within the class. */ - OperQuit("OperQuit", NULL), + OperQuit("operquit", NULL), GenRandom(&HandleGenRandom), IsChannel(&HandleIsChannel), - Rehash(&HandleRehash), IsNick(&HandleIsNick), IsIdent(&HandleIsIdent), OnCheckExemption(&HandleOnCheckExemption) @@ -336,7 +342,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : { case 'c': /* Config filename was set */ - ConfigFileName = optarg; + ConfigFileName = ServerInstance->Config->Paths.PrependConfig(optarg); break; case 0: /* getopt_long_only() set an int variable, just keep going */ @@ -358,7 +364,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : if (do_version) { - std::cout << std::endl << VERSION << " r" << REVISION << std::endl; + std::cout << std::endl << VERSION << " " << REVISION << std::endl; Exit(EXIT_STATUS_NOERROR); } @@ -381,14 +387,14 @@ InspIRCd::InspIRCd(int argc, char** argv) : Logs->AddLogTypes("*", fls, true); } - if (!ServerConfig::FileExists(ConfigFileName.c_str())) + if (!FileSystem::FileExists(ConfigFileName)) { #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"); - if (ServerConfig::FileExists(txtconf.c_str())) + if (FileSystem::FileExists(txtconf)) { ConfigFileName = txtconf; } @@ -458,7 +464,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : this->UIDGen.init(Config->sid); // Create the server user for this server - this->FakeClient = new FakeUser(Config->sid, Config->ServerName); + this->FakeClient = new FakeUser(Config->sid, Config->ServerName, Config->ServerDesc); // This is needed as all new XLines are marked pending until ApplyLines() is called this->XLines->ApplyLines(); @@ -568,7 +574,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : if (!g) { - this->Logs->Log("STARTUP", LOG_DEFAULT, "getgrnam() failed (bad user?): %s", strerror(errno)); + this->Logs->Log("STARTUP", LOG_DEFAULT, "getgrnam(%s) failed (wrong group?): %s", SetGroup.c_str(), strerror(errno)); this->QuickExit(0); } @@ -576,7 +582,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : if (ret == -1) { - this->Logs->Log("STARTUP", LOG_DEFAULT, "setgid() failed (bad user?): %s", strerror(errno)); + this->Logs->Log("STARTUP", LOG_DEFAULT, "setgid() failed (wrong group?): %s", strerror(errno)); this->QuickExit(0); } } @@ -591,7 +597,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : if (!u) { - this->Logs->Log("STARTUP", LOG_DEFAULT, "getpwnam() failed (bad user?): %s", strerror(errno)); + this->Logs->Log("STARTUP", LOG_DEFAULT, "getpwnam(%s) failed (wrong user?): %s", SetUser.c_str(), strerror(errno)); this->QuickExit(0); } @@ -599,7 +605,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : if (ret == -1) { - this->Logs->Log("STARTUP", LOG_DEFAULT, "setuid() failed (bad user?): %s", strerror(errno)); + this->Logs->Log("STARTUP", LOG_DEFAULT, "setuid() failed (wrong user?): %s", strerror(errno)); this->QuickExit(0); } } @@ -701,7 +707,7 @@ void InspIRCd::Run() if ((TIME.tv_sec % 3600) == 0) { Users->GarbageCollect(); - FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect()); + FOREACH_MOD(OnGarbageCollect, ()); } Timers->TickTimers(TIME.tv_sec); @@ -709,7 +715,7 @@ void InspIRCd::Run() if ((TIME.tv_sec % 5) == 0) { - FOREACH_MOD(I_OnBackgroundTimer,OnBackgroundTimer(TIME.tv_sec)); + FOREACH_MOD(OnBackgroundTimer, (TIME.tv_sec)); SNO->FlushSnotices(); } }