summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-12-23 14:06:57 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-12-23 14:06:57 +0000
commit371daf9928def23164b49b39ced1d3cdeb9225b8 (patch)
treee786547ee80ef75eba14e0bb9c67b725bfae21fe
parent089cf1f5fd2ca1d2ca9d49db3c646ecbede67167 (diff)
Refactored /RESTART (and added InspIRCd::Restart(reason))
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
-rw-r--r--include/configreader.h12
-rw-r--r--include/inspircd.h10
-rw-r--r--src/cmd_restart.cpp28
-rw-r--r--src/helperfuncs.cpp22
-rw-r--r--src/inspircd.cpp12
-rw-r--r--src/modules/extra/m_ziplink.cpp2
6 files changed, 50 insertions, 36 deletions
diff --git a/include/configreader.h b/include/configreader.h
index 8416b12bf..3c8a58e64 100644
--- a/include/configreader.h
+++ b/include/configreader.h
@@ -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);
diff --git a/include/inspircd.h b/include/inspircd.h
index 4648eaf69..6cb5c0dd0 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -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,
diff --git a/src/cmd_restart.cpp b/src/cmd_restart.cpp
index c985c1717..73bfce298 100644
--- a/src/cmd_restart.cpp
+++ b/src/cmd_restart.cpp
@@ -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
{
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index dab21744a..9ddfe338f 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -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+");
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 54c3aa0ab..670fb5ef7 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -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__);
diff --git a/src/modules/extra/m_ziplink.cpp b/src/modules/extra/m_ziplink.cpp
index 841591225..ab40acb46 100644
--- a/src/modules/extra/m_ziplink.cpp
+++ b/src/modules/extra/m_ziplink.cpp
@@ -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 = "";