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 1243 by michael, Fri Sep 30 10:47:53 2011 UTC vs.
Revision 1436 by michael, Sun Jun 17 19:31:28 2012 UTC

# Line 27 | Line 27
27   #include "stdinc.h"
28   #include "list.h"
29   #include "modules.h"
30 < #include "s_log.h"
30 > #include "log.h"
31   #include "ircd.h"
32   #include "client.h"
33   #include "send.h"
34 < #include "s_conf.h"
34 > #include "conf.h"
35   #include "numeric.h"
36   #include "parse.h"
37   #include "ircd_defs.h"
# Line 68 | Line 68 | static void mo_modload(struct Client *,
68   static void mo_modlist(struct Client *, struct Client *, int, char *[]);
69   static void mo_modreload(struct Client *, struct Client *, int, char *[]);
70   static void mo_modunload(struct Client *, struct Client *, int, char *[]);
71 static void mo_modrestart(struct Client *, struct Client *, int, char *[]);
71  
72   struct Message modload_msgtab = {
73   "MODLOAD", 0, 0, 2, 0, MFLG_SLOW, 0,
# Line 90 | Line 89 | struct Message modlist_msgtab = {
89    {m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modlist, m_ignore}
90   };
91  
93 struct Message modrestart_msgtab = {
94 "MODRESTART", 0, 0, 0, 0, MFLG_SLOW, 0,
95 {m_unregistered, m_not_oper, m_ignore, m_ignore, mo_modrestart, m_ignore}
96 };
97
92  
93   int
94   modules_valid_suffix(const char *name)
# Line 128 | Line 122 | unload_one_module(const char *name, int
122  
123    if (warn == 1)
124    {
125 <    ilog(L_INFO, "Module %s unloaded", name);
125 >    ilog(LOG_TYPE_IRCD, "Module %s unloaded", name);
126      sendto_realops_flags(UMODE_ALL, L_ALL, "Module %s unloaded", name);
127    }
128  
# Line 142 | Line 136 | unload_one_module(const char *name, int
136   * side effects - loads a module if successful
137   */
138   int
139 < load_a_module(const char *path, int warn, int core)
139 > load_a_module(const char *path, int warn)
140   {
141    lt_dlhandle tmpptr = NULL;
142    const char *mod_basename = NULL;
# Line 156 | Line 150 | load_a_module(const char *path, int warn
150  
151      sendto_realops_flags(UMODE_ALL, L_ALL, "Error loading module %s: %s",
152                           mod_basename, err);
153 <    ilog(L_WARN, "Error loading module %s: %s", mod_basename, err);
153 >    ilog(LOG_TYPE_IRCD, "Error loading module %s: %s", mod_basename, err);
154      return -1;
155    }
156  
# Line 164 | Line 158 | load_a_module(const char *path, int warn
158    {
159      sendto_realops_flags(UMODE_ALL, L_ALL, "Module %s has no module_entry export",
160                           mod_basename);
161 <    ilog(L_WARN, "Module %s has no module_entry export", mod_basename);
161 >    ilog(LOG_TYPE_IRCD, "Module %s has no module_entry export", mod_basename);
162      lt_dlclose(tmpptr);
163      return -1;
164    }
# Line 174 | Line 168 | load_a_module(const char *path, int warn
168    if (EmptyString(modp->version))
169      modp->version = unknown_ver;
170  
177  if (core)
178    modp->flags |= MODULE_FLAG_CORE;
179
171    DupString(modp->name, mod_basename);
172    dlinkAdd(modp, &modp->node, &modules_list);
173  
# Line 188 | Line 179 | load_a_module(const char *path, int warn
179      sendto_realops_flags(UMODE_ALL, L_ALL,
180                           "Module %s [version: %s handle: %p] loaded.",
181                           modp->name, modp->version, tmpptr);
182 <    ilog(L_WARN, "Module %s [version: %s handle: %p] loaded.",
182 >    ilog(LOG_TYPE_IRCD, "Module %s [version: %s handle: %p] loaded.",
183           modp->name, modp->version, tmpptr);
184    }
185  
# Line 207 | Line 198 | modules_init(void)
198   {
199    if (lt_dlinit())
200    {
201 <    ilog(L_ERROR, "Couldn't initialize the libltdl run time dynamic"
201 >    ilog(LOG_TYPE_IRCD, "Couldn't initialize the libltdl run time dynamic"
202           " link library. Exiting.");
203      exit(0);
204    }
# Line 216 | Line 207 | modules_init(void)
207    mod_add_cmd(&modunload_msgtab);
208    mod_add_cmd(&modreload_msgtab);
209    mod_add_cmd(&modlist_msgtab);
219  mod_add_cmd(&modrestart_msgtab);
210   }
211  
212   /* mod_find_path()
# Line 229 | Line 219 | static struct module_path *
219   mod_find_path(const char *path)
220   {
221    dlink_node *ptr;
232  struct module_path *mpath;
222  
223    DLINK_FOREACH(ptr, mod_paths.head)
224    {
225 <    mpath = ptr->data;
225 >    struct module_path *mpath = ptr->data;
226  
227      if (!strcmp(path, mpath->path))
228        return mpath;
# Line 288 | Line 277 | add_conf_module(const char *name)
277   void
278   mod_clear_paths(void)
279   {
291  struct module_path *pathst = NULL;
280    dlink_node *ptr = NULL, *next_ptr = NULL;
281  
282    DLINK_FOREACH_SAFE(ptr, next_ptr, mod_paths.head)
283    {
284 <    pathst = ptr->data;
285 <
298 <    dlinkDelete(&pathst->node, &mod_paths);
299 <    MyFree(pathst);
284 >    dlinkDelete(ptr, &mod_paths);
285 >    MyFree(ptr->data);
286    }
287  
288    DLINK_FOREACH_SAFE(ptr, next_ptr, conf_modules.head)
289    {
290 <    pathst = ptr->data;
291 <
306 <    dlinkDelete(&pathst->node, &conf_modules);
307 <    MyFree(pathst);
290 >    dlinkDelete(ptr, &conf_modules);
291 >    MyFree(ptr->data);
292    }
293   }
294  
# Line 343 | Line 327 | load_all_modules(int warn)
327    struct dirent *ldirent = NULL;
328    char module_fq_name[PATH_MAX + 1];
329  
346  modules_init();
347
330    if ((system_module_dir = opendir(AUTOMODPATH)) == NULL)
331    {
332 <    ilog(L_WARN, "Could not load modules from %s: %s",
332 >    ilog(LOG_TYPE_IRCD, "Could not load modules from %s: %s",
333           AUTOMODPATH, strerror(errno));
334      return;
335    }
# Line 358 | Line 340 | load_all_modules(int warn)
340      {
341         snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s",
342                  AUTOMODPATH, ldirent->d_name);
343 <       load_a_module(module_fq_name, warn, 0);
343 >       load_a_module(module_fq_name, warn);
344      }
345    }
346  
# Line 375 | Line 357 | void
357   load_conf_modules(void)
358   {
359    dlink_node *ptr = NULL;
378  struct module_path *mpath = NULL;
360  
361    DLINK_FOREACH(ptr, conf_modules.head)
362    {
363 <    mpath = ptr->data;
363 >    struct module_path *mpath = ptr->data;
364  
365      if (findmodule_byname(mpath->path) == NULL)
366 <      load_one_module(mpath->path, 0);
366 >      load_one_module(mpath->path);
367    }
368   }
369  
# Line 403 | Line 384 | load_core_modules(int warn)
384      snprintf(module_name, sizeof(module_name), "%s%s",
385               MODPATH, core_module_table[i]);
386  
387 <    if (load_a_module(module_name, warn, 1) == -1)
387 >    if (load_a_module(module_name, warn) == -1)
388      {
389 <      ilog(L_CRIT, "Error loading core module %s: terminating ircd",
389 >      ilog(LOG_TYPE_IRCD, "Error loading core module %s: terminating ircd",
390             core_module_table[i]);
391        exit(EXIT_FAILURE);
392      }
# Line 420 | Line 401 | load_core_modules(int warn)
401   * side effects - module is loaded if found.
402   */
403   int
404 < load_one_module(const char *path, int coremodule)
404 > load_one_module(const char *path)
405   {
406    dlink_node *ptr = NULL;
407    char modpath[PATH_MAX + 1];
# Line 437 | Line 418 | load_one_module(const char *path, int co
418  
419      if (strstr(modpath, "../") == NULL &&
420          strstr(modpath, "/..") == NULL)
440    {
421        if (!stat(modpath, &statbuf))
422 <      {
423 <        if (S_ISREG(statbuf.st_mode))
444 <        {
445 <          /* Regular files only please */
446 <          return load_a_module(modpath, 1, coremodule);
447 <        }
448 <      }
449 <    }
422 >        if (S_ISREG(statbuf.st_mode))  /* Regular files only please */
423 >          return load_a_module(modpath, 1);
424    }
425  
426    sendto_realops_flags(UMODE_ALL, L_ALL,
427                         "Cannot locate module %s", path);
428 <  ilog(L_WARN, "Cannot locate module %s", path);
428 >  ilog(LOG_TYPE_IRCD, "Cannot locate module %s", path);
429    return -1;
430   }
431  
# Line 478 | Line 452 | mo_modload(struct Client *client_p, stru
452      return;
453    }
454  
455 <  load_one_module(parv[1], 0);
455 >  load_one_module(parv[1]);
456   }
457  
458   /* unload a module .. */
# Line 536 | Line 510 | mo_modreload(struct Client *client_p, st
510      return;
511    }
512  
513 +  if (!strcmp(parv[1], "*"))
514 +  {
515 +    unsigned int modnum = 0;
516 +    dlink_node *ptr = NULL, *ptr_next = NULL;
517 +
518 +    sendto_one(source_p, ":%s NOTICE %s :Reloading all modules",
519 +               me.name, source_p->name);
520 +
521 +    modnum = dlink_list_length(&modules_list);
522 +
523 +    DLINK_FOREACH_SAFE(ptr, ptr_next, modules_list.head)
524 +    {
525 +      modp = ptr->data;
526 +      unload_one_module(modp->name, 0);
527 +    }
528 +
529 +    load_all_modules(0);
530 +    load_conf_modules();
531 +    load_core_modules(0);
532 +
533 +    sendto_realops_flags(UMODE_ALL, L_ALL,
534 +                        "Module Restart: %u modules unloaded, %u modules loaded",
535 +                          modnum, dlink_list_length(&modules_list));
536 +    ilog(LOG_TYPE_IRCD, "Module Restart: %u modules unloaded, %u modules loaded",
537 +         modnum, dlink_list_length(&modules_list));
538 +    return;
539 +  }
540 +
541    m_bn = libio_basename(parv[1]);
542  
543    if ((modp = findmodule_byname(m_bn)) == NULL)
# Line 554 | Line 556 | mo_modreload(struct Client *client_p, st
556      return;
557    }
558  
559 <  if ((load_one_module(parv[1], check_core) == -1) && check_core)
559 >  if ((load_one_module(parv[1]) == -1) && check_core)
560    {
561      sendto_realops_flags(UMODE_ALL, L_ALL, "Error reloading core "
562                           "module: %s: terminating ircd", parv[1]);
563 <    ilog(L_CRIT, "Error loading core module %s: terminating ircd", parv[1]);
563 >    ilog(LOG_TYPE_IRCD, "Error loading core module %s: terminating ircd", parv[1]);
564      exit(0);
565    }
566   }
# Line 592 | Line 594 | mo_modlist(struct Client *client_p, stru
594    sendto_one(source_p, form_str(RPL_ENDOFMODLIST),
595               me.name, source_p->name);
596   }
595
596 /* unload and reload all modules */
597 static void
598 mo_modrestart(struct Client *client_p, struct Client *source_p,
599              int parc, char *parv[])
600 {
601  unsigned int modnum = 0;
602  dlink_node *ptr = NULL, *ptr_next = NULL;
603
604  if (!HasOFlag(source_p, OPER_FLAG_MODULE))
605  {
606    sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
607               me.name, source_p->name);
608    return;
609  }
610
611  sendto_one(source_p, ":%s NOTICE %s :Reloading all modules",
612             me.name, source_p->name);
613
614  modnum = dlink_list_length(&modules_list);
615
616  DLINK_FOREACH_SAFE(ptr, ptr_next, modules_list.head)
617  {
618    struct module *modp = ptr->data;
619    unload_one_module(modp->name, 0);
620  }
621
622  load_all_modules(0);
623  load_conf_modules();
624  load_core_modules(0);
625
626  sendto_realops_flags(UMODE_ALL, L_ALL,
627              "Module Restart: %u modules unloaded, %u modules loaded",
628                        modnum, dlink_list_length(&modules_list));
629  ilog(L_WARN, "Module Restart: %u modules unloaded, %u modules loaded",
630       modnum, dlink_list_length(&modules_list));
631 }

Diff Legend

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