+void InspIRCd::Cleanup()
+{
+ std::vector<std::string> mymodnames;
+ int MyModCount = this->GetModuleCount();
+
+ for (unsigned int i = 0; i < stats->BoundPortCount; i++)
+ {
+ /* This calls the constructor and closes the listening socket */
+ delete Config->openSockfd[i];
+ Config->openSockfd[i] = NULL;
+ }
+ stats->BoundPortCount = 0;
+
+ /* We do this more than once, so that any service providers get a
+ * chance to be unhooked by the modules using them, but then get
+ * a chance to be removed themsleves.
+ */
+ for (int tries = 0; tries < 3; tries++)
+ {
+ MyModCount = this->GetModuleCount();
+ mymodnames.clear();
+
+ /* Unload all modules, so they get a chance to clean up their listeners */
+ for (int j = 0; j <= MyModCount; j++)
+ mymodnames.push_back(Config->module_names[j]);
+
+ for (int k = 0; k <= MyModCount; k++)
+ this->UnloadModule(mymodnames[k].c_str());
+ }
+
+ /* Close all client sockets, or the new process inherits them */
+ for (std::vector<userrec*>::const_iterator i = this->local_users.begin(); i != this->local_users.end(); i++)
+ (*i)->CloseSocket();
+
+ /* Close logging */
+ this->Logger->Close();
+}
+
+void InspIRCd::Restart(const std::string &reason)
+{
+ /* SendError flushes each client's queue,
+ * regardless of writeability state
+ */
+ this->SendError(reason);
+
+ this->Cleanup();
+
+ /* Figure out our filename (if theyve renamed it, we're boned) */
+ std::string me = Config->MyDir + "/inspircd";
+
+ 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));
+ }
+}
+