*/
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;
*/
operclass_t operclass;
+ /** Saved argv from startup
+ */
+ char** argv;
+
+ /** Saved argc from startup
+ */
+ int argc;
+
/** Construct a new ServerConfig
*/
ServerConfig(InspIRCd* Instance);
/** 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
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,
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
{
* 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();
}
}
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+");
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__);
void CloseSession(izip_session* session)
{
- if (session->status = IZIP_OPEN)
+ if (session->status == IZIP_OPEN)
{
session->status = IZIP_CLOSED;
session->outbuf = "";