]> jfr.im git - solanum.git/blobdiff - ircd/modules.c
ircd: modules: findmodule_byname(): also check LT_MODULE_EXT here
[solanum.git] / ircd / modules.c
index 0eade506c6d494a6e634fdef33a8234000ae55a6..2e0e0869740f8b8264a7b5c66108c8158059e5d8 100644 (file)
 
 #include <ltdl.h>
 
+#ifndef LT_MODULE_EXT
+#      error "Charybdis requires loadable module support."
+#endif
+
 struct module **modlist = NULL;
 
 static const char *core_module_table[] = {
@@ -202,12 +206,20 @@ int
 findmodule_byname(const char *name)
 {
        int i;
+       char name_ext[PATH_MAX + 1];
+
+       rb_strlcpy(name_ext, name, sizeof basename_ext);
+       rb_strlcat(name_ext, LT_MODULE_EXT, sizeof basename_ext);
 
        for (i = 0; i < num_mods; i++)
        {
                if(!irccmp(modlist[i]->name, name))
                        return i;
+
+               if(!irccmp(modlist[i]->name, name_ext))
+                       return i;
        }
+
        return -1;
 }
 
@@ -223,7 +235,7 @@ load_all_modules(int warn)
        DIR *system_module_dir = NULL;
        struct dirent *ldirent = NULL;
        char module_fq_name[PATH_MAX + 1];
-       int len;
+       size_t module_ext_len = strlen(LT_MODULE_EXT);
 
        modules_init();
 
@@ -241,8 +253,11 @@ load_all_modules(int warn)
 
        while ((ldirent = readdir(system_module_dir)) != NULL)
        {
+               struct stat s;
+               size_t len;
+
                len = strlen(ldirent->d_name);
-               if((len > 3) && !strcmp(ldirent->d_name+len-3, ".la"))
+               if(len > module_ext_len && !strcasecmp(ldirent->d_name + (len - module_ext_len), LT_MODULE_EXT))
                {
                        (void) snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s", AUTOMODPATH, ldirent->d_name);
                        (void) load_a_module(module_fq_name, warn, MAPI_ORIGIN_CORE, 0);
@@ -268,13 +283,13 @@ load_core_modules(int warn)
        for (i = 0; core_module_table[i]; i++)
        {
                snprintf(module_name, sizeof(module_name), "%s/%s%s", MODPATH,
-                           core_module_table[i], ".la");
+                           core_module_table[i], LT_MODULE_EXT);
 
                if(load_a_module(module_name, warn, MAPI_ORIGIN_CORE, 1) == -1)
                {
                        ilog(L_MAIN,
-                            "Error loading core module %s%s: terminating ircd",
-                            core_module_table[i], ".la");
+                            "Error loading core module %s: terminating ircd",
+                            core_module_table[i]);
                        exit(0);
                }
        }
@@ -292,10 +307,9 @@ load_one_module(const char *path, int origin, int coremodule)
        char modpath[PATH_MAX];
        rb_dlink_node *pathst;
        const char *mpath;
-
        struct stat statbuf;
 
-       if (server_state_foreground == 1)
+       if (server_state_foreground)
                inotice("loading module %s ...", path);
 
        if(coremodule != 0)
@@ -308,7 +322,7 @@ load_one_module(const char *path, int origin, int coremodule)
        {
                mpath = pathst->data;
 
-               snprintf(modpath, sizeof(modpath), "%s/%s", mpath, path);
+               snprintf(modpath, sizeof(modpath), "%s/%s%s", mpath, path, LT_MODULE_EXT);
                if((strstr(modpath, "../") == NULL) && (strstr(modpath, "/..") == NULL))
                {
                        if(stat(modpath, &statbuf) == 0)
@@ -809,7 +823,7 @@ load_a_module(const char *path, int warn, int origin, int core)
 
        mod_basename = rb_basename(path);
 
-       tmpptr = lt_dlopen(path);
+       tmpptr = lt_dlopenext(path);
 
        if(tmpptr == NULL)
        {
@@ -822,7 +836,6 @@ load_a_module(const char *path, int warn, int origin, int core)
                return -1;
        }
 
-
        /*
         * _mheader is actually a struct mapi_mheader_*, but mapi_version
         * is always the first member of this structure, so we treate it
@@ -908,12 +921,11 @@ load_a_module(const char *path, int warn, int origin, int core)
                         */
                        if(mheader->mapi_datecode != datecode && mheader->mapi_datecode > 0)
                        {
-                               long int delta = labs(datecode - mheader->mapi_datecode);
+                               long int delta = datecode - mheader->mapi_datecode;
                                if (delta > MOD_WARN_DELTA)
                                {
                                        delta /= 86400;
-                                       iwarn(L_MAIN,
-                                               "Module %s build date is out of sync with ircd build date by %ld days, expect problems",
+                                       iwarn("Module %s build date is out of sync with ircd build date by %ld days, expect problems",
                                                mod_basename, delta);
                                        sendto_realops_snomask(SNO_GENERAL, L_ALL,
                                                "Module %s build date is out of sync with ircd build date by %ld days, expect problems",
@@ -1028,11 +1040,11 @@ load_a_module(const char *path, int warn, int origin, int core)
                }
 
                sendto_realops_snomask(SNO_GENERAL, L_ALL,
-                                    "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at 0x%lx",
+                                    "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at %p",
                                     mod_basename, ver, MAPI_VERSION(*mapi_version), o, description,
-                                    (unsigned long) tmpptr);
-               ilog(L_MAIN, "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at 0x%lx",
-                    mod_basename, ver, MAPI_VERSION(*mapi_version), o, description, (unsigned long) tmpptr);
+                                    (void *) tmpptr);
+               ilog(L_MAIN, "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at %p",
+                    mod_basename, ver, MAPI_VERSION(*mapi_version), o, description, (void *) tmpptr);
        }
        rb_free(mod_basename);
        return 0;