ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/operserv/modrestart.C
Revision: 1.8
Committed: Sat Sep 22 14:27:28 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +5 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * modrestart.C: Module restart.
3 *
4 * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5 * Rights to this code are as documented in COPYING.
6 *
7 *
8 * Portions of this file were derived from sources bearing the following license:
9 * Copyright © 2005-2006 William Pitcock, et al.
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: modrestart.C,v 1.7 2007-09-16 18:54:44 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <ermyth/module.h>
17
18 #if 0
19 static char const rcsid[] = "$Id: modrestart.C,v 1.7 2007-09-16 18:54:44 pippijn Exp $";
20
21 REGISTER_MODULE ("operserv/modrestart", true, "The Ermyth Team <http://ermyth.xinutec.org>");
22
23 static void os_cmd_modrestart (sourceinfo_t *si, int parc, char *parv[]);
24
25 command_t const os_modrestart = { "MODRESTART", N_("Restarts loaded modules."), PRIV_ADMIN, 0, os_cmd_modrestart };
26
27 E cmdvec os_cmdtree;
28 E helpvec os_helptree;
29 extern list_t modules;
30
31 bool
32 _modinit (module *m)
33 {
34 os_cmdtree << os_modrestart;
35 help_addentry (os_helptree, "MODRESTART", "help/operserv/modrestart", NULL);
36
37 return true;
38 }
39
40 void
41 _moddeinit ()
42 {
43 os_cmdtree >> os_modrestart;
44 help_delentry (os_helptree, "MODRESTART");
45 }
46
47 static void
48 os_cmd_modrestart (sourceinfo_t *si, int parc, char *parv[])
49 {
50 node_t *n;
51 int loadedbefore, kept;
52 bool old_silent;
53 bool fail1 = false;
54 bool unloaded_something;
55
56 snoop ("MODRESTART: \2%s\2", get_oper_name (si));
57 logcommand (si, CMDLOG_ADMIN, "MODRESTART");
58 wallops ("Restarting modules by request of \2%s\2", get_oper_name (si));
59
60 old_silent = config_options.silent;
61 config_options.silent = true; /* no wallops */
62
63 loadedbefore = modules.count;
64
65 /* unload everything we can */
66 /* this contorted loop is necessary because unloading a module
67 * may unload other modules */
68 do
69 {
70 unloaded_something = false;
71 LIST_FOREACH (n, modules.head)
72 {
73 module_t *m = static_cast < module_t *>(n->data);
74
75 /* don't touch core modules */
76 /* don't touch ourselves either (ugly way) */
77 if (!m->header->norestart
78 && strcmp (m->header->name, "operserv/main")
79 && strcmp (m->header->name, "operserv/modrestart")
80 && strncmp (m->header->name, "rpc/", 4)
81 )
82 {
83 module_unload (m);
84 unloaded_something = true;
85 break;
86 }
87 }
88 }
89 while (unloaded_something);
90
91 kept = modules.count;
92
93 /* now reload again */
94 module_load_dir (MODDIR "/modules");
95 cold_start = true; /* XXX */
96 fail1 = !conf_rehash ();
97 cold_start = false;
98
99 config_options.silent = old_silent;
100
101 if (fail1)
102 {
103 wallops ("Module restart failed, functionality will be very limited");
104 command_fail (si, fault::nosuch_target, _("Module restart failed, fix it and try again or restart"));
105 }
106 else
107 {
108 wallops ("Module restart: %d modules unloaded; %d kept; %d modules now loaded", loadedbefore - kept, kept, modules.count);
109 command_success_nodata (si, _("Module restart: %d modules unloaded; %d kept; %d modules now loaded"), loadedbefore - kept, kept, modules.count);
110 }
111 }
112 #endif