ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/modules.c
(Generate patch)

Comparing ircd-hybrid-8/src/modules.c (file contents):
Revision 1230 by michael, Thu Sep 22 19:41:19 2011 UTC vs.
Revision 1243 by michael, Fri Sep 30 10:47:53 2011 UTC

# Line 22 | Line 22
22   *  $Id$
23   */
24  
25 + #include "ltdl.h"
26 +
27   #include "stdinc.h"
28   #include "list.h"
29   #include "modules.h"
# Line 30 | Line 32
32   #include "client.h"
33   #include "send.h"
34   #include "s_conf.h"
33 #include "handlers.h"
35   #include "numeric.h"
36   #include "parse.h"
37   #include "ircd_defs.h"
# Line 38 | Line 39
39   #include "memory.h"
40  
41  
42 < dlink_list mod_list = { NULL, NULL, 0 };
42 > static dlink_list modules_list = { NULL, NULL, 0 };
43 >
44 > static const char *unknown_ver = "<unknown>";
45  
46   static const char *core_module_table[] =
47   {
# Line 93 | Line 96 | struct Message modrestart_msgtab = {
96   };
97  
98  
99 + int
100 + modules_valid_suffix(const char *name)
101 + {
102 +  return ((name = strrchr(name, '.'))) && !strcmp(name, ".la");
103 + }
104 +
105 + /* unload_one_module()
106 + *
107 + * inputs       - name of module to unload
108 + *              - 1 to say modules unloaded, 0 to not
109 + * output       - 0 if successful, -1 if error
110 + * side effects - module is unloaded
111 + */
112 + int
113 + unload_one_module(const char *name, int warn)
114 + {
115 +  struct module *modp = NULL;
116 +
117 +  if ((modp = findmodule_byname(name)) == NULL)
118 +    return -1;
119 +
120 +  if (modp->modexit)
121 +   modp->modexit();
122 +
123 +  assert(dlink_list_length(&modules_list) > 0);
124 +  dlinkDelete(&modp->node, &modules_list);
125 +  MyFree(modp->name);
126 +
127 +  lt_dlclose(modp->handle);
128 +
129 +  if (warn == 1)
130 +  {
131 +    ilog(L_INFO, "Module %s unloaded", name);
132 +    sendto_realops_flags(UMODE_ALL, L_ALL, "Module %s unloaded", name);
133 +  }
134 +
135 +  return 0;
136 + }
137 +
138 + /* load_a_module()
139 + *
140 + * inputs       - path name of module, int to notice, int of core
141 + * output       - -1 if error 0 if success
142 + * side effects - loads a module if successful
143 + */
144 + int
145 + load_a_module(const char *path, int warn, int core)
146 + {
147 +  lt_dlhandle tmpptr = NULL;
148 +  const char *mod_basename = NULL;
149 +  struct module *modp = NULL;
150 +
151 +  if (findmodule_byname((mod_basename = libio_basename(path))))
152 +    return 1;
153 +
154 +  if (!(tmpptr = lt_dlopen(path))) {
155 +    const char *err = ((err = lt_dlerror())) ? err : "<unknown>";
156 +
157 +    sendto_realops_flags(UMODE_ALL, L_ALL, "Error loading module %s: %s",
158 +                         mod_basename, err);
159 +    ilog(L_WARN, "Error loading module %s: %s", mod_basename, err);
160 +    return -1;
161 +  }
162 +
163 +  if ((modp = lt_dlsym(tmpptr, "module_entry")) == NULL)
164 +  {
165 +    sendto_realops_flags(UMODE_ALL, L_ALL, "Module %s has no module_entry export",
166 +                         mod_basename);
167 +    ilog(L_WARN, "Module %s has no module_entry export", mod_basename);
168 +    lt_dlclose(tmpptr);
169 +    return -1;
170 +  }
171 +
172 +  modp->handle = tmpptr;
173 +
174 +  if (EmptyString(modp->version))
175 +    modp->version = unknown_ver;
176 +
177 +  if (core)
178 +    modp->flags |= MODULE_FLAG_CORE;
179 +
180 +  DupString(modp->name, mod_basename);
181 +  dlinkAdd(modp, &modp->node, &modules_list);
182 +
183 +  if (modp->modinit)
184 +    modp->modinit();
185 +
186 +  if (warn == 1)
187 +  {
188 +    sendto_realops_flags(UMODE_ALL, L_ALL,
189 +                         "Module %s [version: %s handle: %p] loaded.",
190 +                         modp->name, modp->version, tmpptr);
191 +    ilog(L_WARN, "Module %s [version: %s handle: %p] loaded.",
192 +         modp->name, modp->version, tmpptr);
193 +  }
194 +
195 +  return 0;
196 + }
197 +
198   /*
199   * modules_init
200   *
# Line 103 | Line 205 | struct Message modrestart_msgtab = {
205   void
206   modules_init(void)
207   {
208 <  dynlink_init();
208 >  if (lt_dlinit())
209 >  {
210 >    ilog(L_ERROR, "Couldn't initialize the libltdl run time dynamic"
211 >         " link library. Exiting.");
212 >    exit(0);
213 >  }
214  
215    mod_add_cmd(&modload_msgtab);
216    mod_add_cmd(&modunload_msgtab);
# Line 181 | Line 288 | add_conf_module(const char *name)
288   void
289   mod_clear_paths(void)
290   {
291 <  struct module_path *pathst;
292 <  dlink_node *ptr;
186 <  dlink_node *next_ptr;
291 >  struct module_path *pathst = NULL;
292 >  dlink_node *ptr = NULL, *next_ptr = NULL;
293  
294    DLINK_FOREACH_SAFE(ptr, next_ptr, mod_paths.head)
295    {
# Line 213 | Line 319 | findmodule_byname(const char *name)
319   {
320    dlink_node *ptr = NULL;
321  
322 <  DLINK_FOREACH(ptr, mod_list.head)
322 >  DLINK_FOREACH(ptr, modules_list.head)
323    {
324      struct module *modp = ptr->data;
325  
# Line 471 | Line 577 | mo_modlist(struct Client *client_p, stru
577      return;
578    }
579  
580 <  DLINK_FOREACH(ptr, mod_list.head)
580 >  DLINK_FOREACH(ptr, modules_list.head)
581    {
582      const struct module *modp = ptr->data;
583  
584      if (parc > 1 && !match(parv[1], modp->name))
585        continue;
586  
587 <    sendto_one(source_p, form_str(RPL_MODLIST), me.name, parv[0],
587 >    sendto_one(source_p, form_str(RPL_MODLIST), me.name, source_p->name,
588                 modp->name, modp->handle,
589                 modp->version, (modp->flags & MODULE_FLAG_CORE) ?"(core)":"");
590    }
# Line 505 | Line 611 | mo_modrestart(struct Client *client_p, s
611    sendto_one(source_p, ":%s NOTICE %s :Reloading all modules",
612               me.name, source_p->name);
613  
614 <  modnum = dlink_list_length(&mod_list);
614 >  modnum = dlink_list_length(&modules_list);
615  
616 <  DLINK_FOREACH_SAFE(ptr, ptr_next, mod_list.head)
616 >  DLINK_FOREACH_SAFE(ptr, ptr_next, modules_list.head)
617    {
618      struct module *modp = ptr->data;
619      unload_one_module(modp->name, 0);
# Line 519 | Line 625 | mo_modrestart(struct Client *client_p, s
625  
626    sendto_realops_flags(UMODE_ALL, L_ALL,
627                "Module Restart: %u modules unloaded, %u modules loaded",
628 <                        modnum, dlink_list_length(&mod_list));
628 >                        modnum, dlink_list_length(&modules_list));
629    ilog(L_WARN, "Module Restart: %u modules unloaded, %u modules loaded",
630 <       modnum, dlink_list_length(&mod_list));
630 >       modnum, dlink_list_length(&modules_list));
631   }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)