mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-10 02:59:01 -04:00
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
This commit is contained in:
parent
089cf1f5fd
commit
371daf9928
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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+");
|
||||
|
@ -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__);
|
||||
|
@ -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 = "";
|
||||
|
Loading…
x
Reference in New Issue
Block a user