1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 #include "commands/cmd_rehash.h"
20 extern "C" DllExport Command* init_command(InspIRCd* Instance)
22 return new CommandRehash(Instance);
25 CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, User *user)
27 std::string old_disabled = ServerInstance->Config->DisabledCommands;
29 if (parameters.size() && parameters[0][0] != '-')
31 if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0]))
33 FOREACH_MOD(I_OnRehash,OnRehash(user, parameters[0]));
34 return CMD_SUCCESS; // rehash for a server, and not for us
37 else if (parameters.size())
39 FOREACH_MOD(I_OnRehash,OnRehash(user, parameters[0]));
44 FOREACH_MOD(I_OnRehash,OnRehash(user, ""));
47 user->WriteNumeric(RPL_REHASHING, "%s %s :Rehashing",user->nick.c_str(),ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
49 ServerInstance->PI->SendUserNotice(user, std::string("*** Rehashing server ") + ServerInstance->ConfigFileName);
52 std::string m = user->nick + " is rehashing config file " + ServerConfig::CleanFilename(ServerInstance->ConfigFileName) + " on " + ServerInstance->Config->ServerName;
53 ServerInstance->SNO->WriteToSnoMask('A', m);
54 ServerInstance->Logs->CloseLogs();
56 if (!ServerInstance->OpenLog(ServerInstance->Config->argv, ServerInstance->Config->argc))
58 m = std::string("ERROR: Could not open logfile ") + ServerInstance->Config->logpath + ":" + strerror(errno);
59 ServerInstance->SNO->WriteToSnoMask('A', m);
62 ServerInstance->RehashUsersAndChans();
63 FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
65 if (!ServerInstance->ConfigThread)
67 ServerInstance->Config->RehashUserUID = user->uuid;
68 ServerInstance->Config->RehashParameter = parameters.size() ? parameters[0] : "";
70 ServerInstance->ConfigThread = new ConfigReaderThread(ServerInstance, false, ServerInstance->Config->RehashUserUID);
71 ServerInstance->Threads->Create(ServerInstance->ConfigThread);
76 * A rehash is already in progress! ahh shit.
77 * XXX, todo: we should find some way to kill runaway rehashes that are blocking, this is a major problem for unrealircd users
80 user->WriteServ("NOTICE %s :*** Could not rehash: A rehash is already in progress.", user->nick.c_str());
82 ServerInstance->PI->SendUserNotice(user, "*** Could not rehash: A rehash is already in progress.");