/** * modrestart.C: Module restart. * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2005-2006 William Pitcock, et al. * Rights to this code are as documented in doc/pod/license.pod. * * $Id: modrestart.C,v 1.8 2007/09/22 14:27:28 pippijn Exp $ */ #include "atheme.h" #include #if 0 static char const rcsid[] = "$Id: modrestart.C,v 1.8 2007/09/22 14:27:28 pippijn Exp $"; REGISTER_MODULE ("operserv/modrestart", true, "The Ermyth Team "); static void os_cmd_modrestart (sourceinfo_t *si, int parc, char *parv[]); command_t const os_modrestart = { "MODRESTART", N_("Restarts loaded modules."), PRIV_ADMIN, 0, os_cmd_modrestart }; E cmdvec os_cmdtree; E helpvec os_helptree; extern list_t modules; bool _modinit (module *m) { os_cmdtree << os_modrestart; help_addentry (os_helptree, "MODRESTART", "help/operserv/modrestart", NULL); return true; } void _moddeinit () { os_cmdtree >> os_modrestart; help_delentry (os_helptree, "MODRESTART"); } static void os_cmd_modrestart (sourceinfo_t *si, int parc, char *parv[]) { node_t *n; int loadedbefore, kept; bool old_silent; bool fail1 = false; bool unloaded_something; snoop ("MODRESTART: \2%s\2", get_oper_name (si)); logcommand (si, CMDLOG_ADMIN, "MODRESTART"); wallops ("Restarting modules by request of \2%s\2", get_oper_name (si)); old_silent = config_options.silent; config_options.silent = true; /* no wallops */ loadedbefore = modules.count; /* unload everything we can */ /* this contorted loop is necessary because unloading a module * may unload other modules */ do { unloaded_something = false; LIST_FOREACH (n, modules.head) { module_t *m = static_cast < module_t *>(n->data); /* don't touch core modules */ /* don't touch ourselves either (ugly way) */ if (!m->header->norestart && strcmp (m->header->name, "operserv/main") && strcmp (m->header->name, "operserv/modrestart") && strncmp (m->header->name, "rpc/", 4) ) { module_unload (m); unloaded_something = true; break; } } } while (unloaded_something); kept = modules.count; /* now reload again */ module_load_dir (MODDIR "/modules"); cold_start = true; /* XXX */ fail1 = !conf_rehash (); cold_start = false; config_options.silent = old_silent; if (fail1) { wallops ("Module restart failed, functionality will be very limited"); command_fail (si, fault::nosuch_target, _("Module restart failed, fix it and try again or restart")); } else { wallops ("Module restart: %d modules unloaded; %d kept; %d modules now loaded", loadedbefore - kept, kept, modules.count); command_success_nodata (si, _("Module restart: %d modules unloaded; %d kept; %d modules now loaded"), loadedbefore - kept, kept, modules.count); } } #endif