]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Convert LocalUserList to an intrusively linked list
[user/henk/code/inspircd.git] / src / inspircd.cpp
index 59c65b931d34d6617b66e997695eef139c9def08..12962d92d6391dcd8b3033477adbe22f58ce2547 100644 (file)
@@ -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 */
@@ -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);
                }
        }