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/trunk/src/modules.c (file contents):
Revision 3356 by michael, Sun Apr 20 14:48:33 2014 UTC vs.
Revision 8660 by michael, Sun Nov 18 12:55:59 2018 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 2000-2014 ircd-hybrid development team
4 > *  Copyright (c) 2000-2018 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 15 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20   */
21  
# Line 45 | Line 45 | static dlink_list modules_list;
45   static dlink_list modules_path;
46   static dlink_list modules_conf;
47  
48 < static const char *unknown_ver = "<unknown>";
49 < static const char *core_module_table[] =
48 > static const char *const unknown_ver = "<unknown>";
49 > static const char *const core_module_table[] =
50   {
51    "m_bmask.la",
52    "m_die.la",
# Line 73 | Line 73 | modules_get_list(void)
73    return &modules_list;
74   }
75  
76 < int
76 > bool
77   modules_valid_suffix(const char *name)
78   {
79 <  return ((name = strrchr(name, '.'))) && !strcmp(name, ".la");
79 >  return ((name = strrchr(name, '.'))) && strcmp(name, ".la") == 0;
80   }
81  
82   /* unload_one_module()
83   *
84   * inputs       - name of module to unload
85   *              - 1 to say modules unloaded, 0 to not
86 < * output       - 0 if successful, -1 if error
86 > * output       - true if successful, false if error
87   * side effects - module is unloaded
88   */
89 < int
90 < unload_one_module(const char *name, int warn)
89 > bool
90 > unload_one_module(const char *name, bool warn)
91   {
92    struct module *modp = NULL;
93  
94    if ((modp = findmodule_byname(name)) == NULL)
95 <    return -1;
95 >    return false;
96  
97    if (modp->modexit)
98     modp->modexit();
99  
100  assert(dlink_list_length(&modules_list) > 0);
100    dlinkDelete(&modp->node, &modules_list);
101 <  MyFree(modp->name);
101 >  xfree(modp->name);
102  
103    lt_dlclose(modp->handle);
104  
105 <  if (warn == 1)
105 >  if (warn == true)
106    {
107      ilog(LOG_TYPE_IRCD, "Module %s unloaded", name);
108 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
108 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
109                           "Module %s unloaded", name);
110    }
111  
112 <  return 0;
112 >  return true;
113   }
114  
115   /* load_a_module()
116   *
117   * inputs       - path name of module, int to notice, int of core
118 < * output       - -1 if error 0 if success
118 > * output       - false if error true if success
119   * side effects - loads a module if successful
120   */
121 < int
122 < load_a_module(const char *path, int warn)
121 > bool
122 > load_a_module(const char *path, bool warn)
123   {
124    lt_dlhandle tmpptr = NULL;
125    const char *mod_basename = NULL;
126    struct module *modp = NULL;
127  
128    if (findmodule_byname((mod_basename = libio_basename(path))))
129 <    return 1;
129 >    return false;
130  
131 <  if (!(tmpptr = lt_dlopen(path)))
131 >  if ((tmpptr = lt_dlopen(path)) == NULL)
132    {
133      const char *err = ((err = lt_dlerror())) ? err : "<unknown>";
134  
135 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
135 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
136                           "Error loading module %s: %s",
137                           mod_basename, err);
138      ilog(LOG_TYPE_IRCD, "Error loading module %s: %s", mod_basename, err);
139 <    return -1;
139 >    return false;
140    }
141  
142    if ((modp = lt_dlsym(tmpptr, "module_entry")) == NULL)
143    {
144      const char *err = ((err = lt_dlerror())) ? err : "<unknown>";
145  
146 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
146 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
147                           "Error loading module %s: %s",
148                           mod_basename, err);
149      ilog(LOG_TYPE_IRCD, "Error loading module %s: %s", mod_basename, err);
150      lt_dlclose(tmpptr);
151 <    return -1;
151 >    return false;
152    }
153  
154    modp->handle = tmpptr;
# Line 163 | Line 162 | load_a_module(const char *path, int warn
162    if (modp->modinit)
163      modp->modinit();
164  
165 <  if (warn == 1)
165 >  if (warn == true)
166    {
167 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
167 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
168                           "Module %s [version: %s handle: %p] loaded.",
169                           modp->name, modp->version, tmpptr);
170      ilog(LOG_TYPE_IRCD, "Module %s [version: %s handle: %p] loaded.",
171           modp->name, modp->version, tmpptr);
172    }
173  
174 <  return 0;
174 >  return true;
175   }
176  
177   /*
# Line 189 | Line 188 | modules_init(void)
188    {
189      ilog(LOG_TYPE_IRCD, "Couldn't initialize the libltdl run time dynamic"
190           " link library. Exiting.");
191 <    exit(0);
191 >    exit(EXIT_FAILURE);
192    }
193   }
194  
# Line 202 | Line 201 | modules_init(void)
201   static struct module_path *
202   mod_find_path(const char *path)
203   {
204 <  dlink_node *ptr = NULL;
204 >  dlink_node *node;
205  
206 <  DLINK_FOREACH(ptr, modules_path.head)
206 >  DLINK_FOREACH(node, modules_path.head)
207    {
208 <    struct module_path *mpath = ptr->data;
208 >    struct module_path *mpath = node->data;
209  
210 <    if (!strcmp(path, mpath->path))
210 >    if (strcmp(path, mpath->path) == 0)
211        return mpath;
212    }
213  
# Line 229 | Line 228 | mod_add_path(const char *path)
228    if (mod_find_path(path))
229      return;
230  
231 <  pathst = MyMalloc(sizeof(struct module_path));
232 <
234 <  strlcpy(pathst->path, path, sizeof(pathst->path));
231 >  pathst = xcalloc(sizeof(*pathst));
232 >  pathst->path = xstrdup(path);
233    dlinkAdd(pathst, &pathst->node, &modules_path);
234   }
235  
# Line 246 | Line 244 | add_conf_module(const char *name)
244   {
245    struct module_path *pathst;
246  
247 <  pathst = MyMalloc(sizeof(struct module_path));
248 <
251 <  strlcpy(pathst->path, name, sizeof(pathst->path));
247 >  pathst = xcalloc(sizeof(*pathst));
248 >  pathst->path = xstrdup(name);
249    dlinkAdd(pathst, &pathst->node, &modules_conf);
250   }
251  
# Line 259 | Line 256 | add_conf_module(const char *name)
256   * side effects - clear the lists of paths and conf modules
257   */
258   void
259 < mod_clear_paths(void)
259 > modules_conf_clear(void)
260   {
261 <  dlink_node *ptr = NULL, *ptr_next = NULL;
265 <
266 <  DLINK_FOREACH_SAFE(ptr, ptr_next, modules_path.head)
261 >  while (modules_path.head)
262    {
263 <    dlinkDelete(ptr, &modules_path);
264 <    MyFree(ptr->data);
263 >    struct module_path *path = modules_path.head->data;
264 >
265 >    dlinkDelete(&path->node, &modules_path);
266 >    xfree(path->path);
267 >    xfree(path);
268    }
269  
270 <  DLINK_FOREACH_SAFE(ptr, ptr_next, modules_conf.head)
270 >  while (modules_conf.head)
271    {
272 <    dlinkDelete(ptr, &modules_conf);
273 <    MyFree(ptr->data);
272 >    struct module_path *path = modules_conf.head->data;
273 >
274 >    dlinkDelete(&path->node, &modules_conf);
275 >    xfree(path->path);
276 >    xfree(path);
277    }
278   }
279  
# Line 285 | Line 286 | mod_clear_paths(void)
286   struct module *
287   findmodule_byname(const char *name)
288   {
289 <  dlink_node *ptr = NULL;
289 >  dlink_node *node;
290  
291 <  DLINK_FOREACH(ptr, modules_list.head)
291 >  DLINK_FOREACH(node, modules_list.head)
292    {
293 <    struct module *modp = ptr->data;
293 >    struct module *modp = node->data;
294  
295 <    if (!strcmp(modp->name, name))
295 >    if (strcmp(modp->name, name) == 0)
296        return modp;
297    }
298  
# Line 305 | Line 306 | findmodule_byname(const char *name)
306   * side effects - load all modules found in autoload directory
307   */
308   void
309 < load_all_modules(int warn)
309 > load_all_modules(bool warn)
310   {
311    DIR *system_module_dir = NULL;
312    struct dirent *ldirent = NULL;
# Line 340 | Line 341 | load_all_modules(int warn)
341   void
342   load_conf_modules(void)
343   {
344 <  dlink_node *ptr = NULL;
344 >  dlink_node *node;
345  
346 <  DLINK_FOREACH(ptr, modules_conf.head)
346 >  DLINK_FOREACH(node, modules_conf.head)
347    {
348 <    struct module_path *mpath = ptr->data;
348 >    struct module_path *mpath = node->data;
349  
350      if (findmodule_byname(mpath->path) == NULL)
351        load_one_module(mpath->path);
# Line 358 | Line 359 | load_conf_modules(void)
359   * side effects - core modules are loaded, if any fail, kill ircd
360   */
361   void
362 < load_core_modules(int warn)
362 > load_core_modules(bool warn)
363   {
364    char module_name[HYB_PATH_MAX + 1];
365  
# Line 367 | Line 368 | load_core_modules(int warn)
368      snprintf(module_name, sizeof(module_name), "%s%s",
369               MODPATH, core_module_table[i]);
370  
371 <    if (load_a_module(module_name, warn) == -1)
371 >    if (load_a_module(module_name, warn) == false)
372      {
373        ilog(LOG_TYPE_IRCD, "Error loading core module %s: terminating ircd",
374             core_module_table[i]);
# Line 383 | Line 384 | load_core_modules(int warn)
384   * output       - -1 if error
385   * side effects - module is loaded if found.
386   */
387 < int
387 > bool
388   load_one_module(const char *name)
389   {
390 <  dlink_node *ptr = NULL;
390 >  dlink_node *node;
391    char path[HYB_PATH_MAX + 1];
392    struct stat statbuf;
393  
394 <  DLINK_FOREACH(ptr, modules_path.head)
394 >  DLINK_FOREACH(node, modules_path.head)
395    {
396 <    const struct module_path *mpath = ptr->data;
396 >    const struct module_path *mpath = node->data;
397  
398      snprintf(path, sizeof(path), "%s/%s", mpath->path, name);
399  
400 <    if (!modules_valid_suffix(name))
400 >    if (modules_valid_suffix(name) == false)
401        continue;
402  
403      if (strstr(path, "../") == NULL &&
404          strstr(path, "/..") == NULL)
405 <      if (!stat(path, &statbuf))
405 >      if (stat(path, &statbuf) == 0)
406          if (S_ISREG(statbuf.st_mode))  /* Regular files only please */
407 <          return load_a_module(path, 1);
407 >          return load_a_module(path, true);
408    }
409  
410 <  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
410 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
411                         "Cannot locate module %s", name);
412    ilog(LOG_TYPE_IRCD, "Cannot locate module %s", name);
413 <  return -1;
413 >  return false;
414   }

Comparing ircd-hybrid/trunk/src/modules.c (property svn:keywords):
Revision 3356 by michael, Sun Apr 20 14:48:33 2014 UTC vs.
Revision 8660 by michael, Sun Nov 18 12:55:59 2018 UTC

# Line 1 | Line 1
1 < Id Revision
1 > Id

Diff Legend

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