1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 #include "commands/cmd_rehash.h"
19 extern "C" DllExport Command* init_command(InspIRCd* Instance)
21 return new CommandRehash(Instance);
24 CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, User *user)
26 std::string param = parameters.size() ? parameters[0] : "";
28 FOREACH_MOD(I_OnPreRehash,OnPreRehash(user, param));
32 // standard rehash of local server
34 else if (param.find_first_of("*.") != std::string::npos)
36 // rehash of servers by server name (with wildcard)
37 if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0]))
39 // Doesn't match us. PreRehash is already done, nothing left to do
45 // parameterized rehash
47 // the leading "-" is optional; remove it if present.
49 param = param.substr(1);
51 FOREACH_MOD(I_OnModuleRehash,OnModuleRehash(user, param));
55 // Rehash for me. Try to start the rehash thread
56 if (!ServerInstance->ConfigThread)
58 std::string m = user->nick + " is rehashing config file " + ServerConfig::CleanFilename(ServerInstance->ConfigFileName) + " on " + ServerInstance->Config->ServerName;
59 ServerInstance->SNO->WriteGlobalSno('a', m);
62 user->WriteNumeric(RPL_REHASHING, "%s %s :Rehashing",
63 user->nick.c_str(),ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
65 ServerInstance->PI->SendUserNotice(user, std::string("*** Rehashing server ") +
66 ServerConfig::CleanFilename(ServerInstance->ConfigFileName));
68 /* Don't do anything with the logs here -- logs are restarted
69 * after the config thread has completed.
72 ServerInstance->RehashUsersAndChans();
73 FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
76 ServerInstance->ConfigThread = new ConfigReaderThread(ServerInstance, user->uuid);
77 ServerInstance->Threads->Start(ServerInstance->ConfigThread);
84 * A rehash is already in progress! ahh shit.
85 * XXX, todo: we should find some way to kill runaway rehashes that are blocking, this is a major problem for unrealircd users
88 user->WriteServ("NOTICE %s :*** Could not rehash: A rehash is already in progress.", user->nick.c_str());
90 ServerInstance->PI->SendUserNotice(user, "*** Could not rehash: A rehash is already in progress.");