]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Refactored /RESTART (and added InspIRCd::Restart(reason))
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 23 Dec 2006 14:06:57 +0000 (14:06 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 23 Dec 2006 14:06:57 +0000 (14:06 +0000)
Fixed bug in m_ziplinks, assigning instead of testing a var (gcc 4.1.1 picked up on this, 3.4 didnt)

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6067 e03df62e-2008-0410-955e-edbf42e46eb7

include/configreader.h
include/inspircd.h
src/cmd_restart.cpp
src/helperfuncs.cpp
src/inspircd.cpp
src/modules/extra/m_ziplink.cpp

index 8416b12bf8cc464ccec31b35b586fa1c2b9994b4..3c8a58e64e57c3968fa88edb179598c291cf4230 100644 (file)
@@ -479,6 +479,10 @@ class ServerConfig : public Extensible
         */
        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;
@@ -505,6 +509,14 @@ class ServerConfig : public Extensible
         */
        operclass_t operclass;
 
+       /** Saved argv from startup
+        */
+       char** argv;
+
+       /** Saved argc from startup
+        */
+       int argc;
+
        /** Construct a new ServerConfig
         */
        ServerConfig(InspIRCd* Instance);
index 4648eaf69140b84325bb28a516af9c9480fa15c5..6cb5c0dd044b4972f45e0df54a6496f5a542ec3b 100644 (file)
@@ -696,7 +696,7 @@ class InspIRCd : public classbase
        /** Send an error notice to all local users, opered and unopered
         * @param s The error string to send
         */
-       void SendError(const char *s);
+       void SendError(const std::string &s);
 
        /** For use with Module::Prioritize().
         * When the return value of this function is returned from
@@ -1113,6 +1113,14 @@ class InspIRCd : public classbase
 
        void SendWhoisLine(userrec* user, userrec* dest, int numeric, const char* format, ...);
 
+       /** Restart the server.
+        * This function will not return. If an error occurs,
+        * it will throw an instance of CoreException.
+        * @param reason The restart reason to show to all clients
+        * @throw CoreException An instance of CoreException indicating the error from execv().
+        */
+       void Restart(const std::string &reason);
+
        /** Begin execution of the server.
         * NOTE: this function NEVER returns. Internally,
         * after performing some initialisation routines,
index c985c17171a03de093c448067f39fbe11c45c751..73bfce298eb51cc7603b07cc3f26a8ee28a5359e 100644 (file)
@@ -24,37 +24,11 @@ extern "C" command_t* init_command(InspIRCd* Instance)
 
 CmdResult cmd_restart::Handle (const char** parameters, int pcnt, userrec *user)
 {
-       char *argv[32];
        ServerInstance->Log(DEFAULT,"Restart: %s",user->nick);
        if (!strcmp(parameters[0],ServerInstance->Config->restartpass))
        {
                ServerInstance->WriteOpers("*** RESTART command from %s!%s@%s, restarting server.",user->nick,user->ident,user->host);
-
-               argv[0] = ServerInstance->Config->MyExecutable;
-               argv[1] = "-wait";
-               if (ServerInstance->Config->nofork)
-               {
-                       argv[2] = "-nofork";
-               }
-               else
-               {
-                       argv[2] = NULL;
-               }
-               argv[3] = NULL;
-               
-               // close ALL file descriptors
-               ServerInstance->SendError("Server restarting.");
-               sleep(1);
-               for (int i = 0; i < MAX_DESCRIPTORS; i++)
-               {
-                       shutdown(i,2);
-                       close(i);
-               }
-               sleep(2);
-               
-               execv(ServerInstance->Config->MyExecutable,argv);
-
-               exit(0);
+               ServerInstance->Restart("Server restarting");
        }
        else
        {
index dab21744aafaf1780f0751cd03b9584903156dd9..9ddfe338ff6b11e4e0664a94cf2993d1a456ef6e 100644 (file)
@@ -274,20 +274,24 @@ chanrec* InspIRCd::FindChan(const std::string &chan)
  * sends out an error notice to all connected clients (not to be used
  * lightly!)
  */
-void InspIRCd::SendError(const char *s)
+void InspIRCd::SendError(const std::string &s)
 {
        for (std::vector<userrec*>::const_iterator i = this->local_users.begin(); i != this->local_users.end(); i++)
        {
-               userrec* t = (userrec*)(*i);
-               if (t->registered == REG_ALL)
+               if ((*i)->registered == REG_ALL)
                {
-                       t->WriteServ("NOTICE %s :%s",t->nick,s);
+                       (*i)->WriteServ("NOTICE %s :%s",(*i)->nick,s.c_str());
                }
                else
                {
-                       // fix - unregistered connections receive ERROR, not NOTICE
-                       t->Write("ERROR :%s",s);
+                       /* Unregistered connections receive ERROR, not a NOTICE */
+                       (*i)->Write("ERROR :" + s);
                }
+               /* This might generate a whole load of EAGAIN, but we dont really
+                * care about this, as if we call SendError something catastrophic
+                * has occured anyway, and we wont receive the events for these.
+                */
+               (*i)->FlushWriteBuf();
        }
 }
 
@@ -423,11 +427,15 @@ bool InspIRCd::IsNick(const char* n)
 
 void InspIRCd::OpenLog(char** argv, int argc)
 {
+       Config->MyDir = ServerConfig::GetFullProgDir(argv,argc);
+       Config->argv = argv;
+       Config->argc = argc;
+
        if (!*this->LogFileName)
        {
                if (Config->logpath == "")
                {
-                       Config->logpath = ServerConfig::GetFullProgDir(argv,argc) + "/ircd.log";
+                       Config->logpath = Config->MyDir + "/ircd.log";
                }
 
                Config->log_file = fopen(Config->logpath.c_str(),"a+");
index 54c3aa0abdbae606d71402bc179b5efb1af7b784..670fb5ef7be35f7af32ef8a7ce5e8e0515cf7ec1 100644 (file)
@@ -66,6 +66,18 @@ void InspIRCd::Exit(int status)
        exit (status);
 }
 
+void InspIRCd::Restart(const std::string &reason)
+{
+       this->SendError(reason);
+       std::string me = Config->MyDir + "/inspircd";
+       this->Logger->Close();
+       if (execv(me.c_str(), Config->argv) == -1)
+       {
+               /* Will raise a SIGABRT if not trapped */
+               throw CoreException(std::string("Failed to execv()! error: ") + strerror(errno));
+       }
+}
+
 void InspIRCd::Start()
 {
        printf("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__);
index 8415912259acb17953418f4e252bc48733ab7027..ab40acb46556514faa9c7241622db6ca048523a3 100644 (file)
@@ -443,7 +443,7 @@ class ModuleZLib : public Module
        
        void CloseSession(izip_session* session)
        {
-               if (session->status = IZIP_OPEN)
+               if (session->status == IZIP_OPEN)
                {
                        session->status = IZIP_CLOSED;
                        session->outbuf = "";