<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7986">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">loader: Remove global symbol only startup phase.<br><br>Dependency loader is now in place so we no longer need a separate loader<br>phase for global symbols only.  This simplifies the loader and allows us<br>to minimize calls to dlopen.<br><br>Change-Id: I33e3174d67f3b4552d3d536326dcaf0ebabb097d<br>---<br>M main/loader.c<br>1 file changed, 15 insertions(+), 47 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/86/7986/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/loader.c b/main/loader.c<br>index a942f90..62a97fc 100644<br>--- a/main/loader.c<br>+++ b/main/loader.c<br>@@ -796,8 +796,6 @@<br> #endif<br> }<br> <br>-#define MODULE_LOCAL_ONLY (void *)-1<br>-<br> /*!<br>  * \internal<br>  * \brief Attempt to dlopen a module.<br>@@ -844,12 +842,11 @@<br>        return mod;<br> }<br> <br>-static struct ast_module *load_dynamic_module(const char *resource_in, unsigned int global_symbols_only, unsigned int suppress_logging)<br>+static struct ast_module *load_dynamic_module(const char *resource_in, unsigned int suppress_logging)<br> {<br>      char fn[PATH_MAX];<br>    struct ast_module *mod;<br>       size_t resource_in_len = strlen(resource_in);<br>-        int exports_globals;<br>  const char *so_ext = "";<br> <br>         if (resource_in_len < 4 || strcasecmp(resource_in + resource_in_len - 3, ".so")) {<br>@@ -858,31 +855,18 @@<br> <br>     snprintf(fn, sizeof(fn), "%s/%s%s", ast_config_AST_MODULE_DIR, resource_in, so_ext);<br> <br>-    /* Try loading in quiet mode first with flags to export global symbols.<br>-       * If the module does not want to export globals we will close and reopen. */<br>-        mod = load_dlopen(resource_in, so_ext, fn,<br>-           global_symbols_only ? RTLD_NOW | RTLD_GLOBAL : RTLD_NOW | RTLD_LOCAL,<br>-                suppress_logging);<br>+   /* Try loading in quiet mode first with RTLD_LOCAL.  The majority of modules do not<br>+   * export symbols so this allows the least number of calls to dlopen. */<br>+     mod = load_dlopen(resource_in, so_ext, fn, RTLD_NOW | RTLD_LOCAL, suppress_logging);<br> <br>-      if (!mod) {<br>-          return NULL;<br>- }<br>-<br>- exports_globals = ast_test_flag(mod->info, AST_MODFLAG_GLOBAL_SYMBOLS);<br>-   if ((global_symbols_only && exports_globals) || (!global_symbols_only && !exports_globals)) {<br>-                /* The first dlopen had the correct flags. */<br>+        if (!mod || !ast_test_flag(mod->info, AST_MODFLAG_GLOBAL_SYMBOLS)) {<br>               return mod;<br>   }<br> <br>  /* Close the module so we can reopen with correct flags. */<br>   logged_dlclose(resource_in, mod->lib);<br>-    if (global_symbols_only) {<br>-           return MODULE_LOCAL_ONLY;<br>-    }<br> <br>- return load_dlopen(resource_in, so_ext, fn,<br>-          exports_globals ? RTLD_NOW | RTLD_GLOBAL : RTLD_NOW | RTLD_LOCAL,<br>-            0);<br>+  return load_dlopen(resource_in, so_ext, fn, RTLD_NOW | RTLD_GLOBAL, 0);<br> }<br> <br> int modules_shutdown(void)<br>@@ -1435,7 +1419,7 @@<br>  *<br>  *  If the module_vector is not provided, the module's load function will be executed<br>  *  immediately */<br>-static enum ast_module_load_result load_resource(const char *resource_name, unsigned int global_symbols_only, unsigned int suppress_logging, struct module_vector *resource_heap, int required)<br>+static enum ast_module_load_result load_resource(const char *resource_name, unsigned int suppress_logging, struct module_vector *resource_heap, int required)<br> {<br>        struct ast_module *mod;<br>       enum ast_module_load_result res = AST_MODULE_LOAD_SUCCESS;<br>@@ -1445,17 +1429,9 @@<br>                    ast_log(LOG_WARNING, "Module '%s' already exists.\n", resource_name);<br>                       return AST_MODULE_LOAD_DECLINE;<br>               }<br>-            if (global_symbols_only && !ast_test_flag(mod->info, AST_MODFLAG_GLOBAL_SYMBOLS))<br>-                 return AST_MODULE_LOAD_SKIP;<br>  } else {<br>-             mod = load_dynamic_module(resource_name, global_symbols_only, suppress_logging);<br>-             if (mod == MODULE_LOCAL_ONLY) {<br>-                              return AST_MODULE_LOAD_SKIP;<br>-         }<br>+            mod = load_dynamic_module(resource_name, suppress_logging);<br>           if (!mod) {<br>-                  if (!global_symbols_only) {<br>-                          ast_log(LOG_WARNING, "Module '%s' could not be loaded.\n", resource_name);<br>-                 }<br>                     return required ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_DECLINE;<br>          }<br> <br>@@ -1498,7 +1474,7 @@<br> {<br>       int res;<br>      AST_DLLIST_LOCK(&module_list);<br>-   res = load_resource(resource_name, 0, 0, NULL, 0);<br>+   res = load_resource(resource_name, 0, NULL, 0);<br>       if (!res) {<br>           ast_test_suite_event_notify("MODULE_LOAD", "Message: %s", resource_name);<br>         }<br>@@ -1655,7 +1631,7 @@<br> /*! loads modules in order by load_pri, updates mod_count<br>  \return -1 on failure to load module, -2 on failure to load required module, otherwise 0<br> */<br>-static int load_resource_list(struct load_order *load_order, unsigned int global_symbols, int *mod_count)<br>+static int load_resource_list(struct load_order *load_order, int *mod_count)<br> {<br>  struct module_vector resource_heap;<br>   struct load_order_entry *order;<br>@@ -1678,8 +1654,8 @@<br>                enum ast_module_load_result lres;<br> <br>          /* Suppress log messages unless this is the last pass */<br>-             lres = load_resource(order->resource, global_symbols, 1, &resource_heap, order->required);<br>-         ast_debug(3, "PASS 0: %-46s %d %d\n", order->resource, lres, global_symbols);<br>+           lres = load_resource(order->resource, 1, &resource_heap, order->required);<br>+         ast_debug(3, "PASS 0: %-46s %d\n", order->resource, lres);<br>               switch (lres) {<br>               case AST_MODULE_LOAD_SUCCESS:<br>                         /* We're supplying a heap so SUCCESS isn't possible but we still have to test for it. */<br>@@ -1717,8 +1693,8 @@<br>                       enum ast_module_load_result lres;<br> <br>                  /* Suppress log messages unless this is the last pass */<br>-                     lres = load_resource(order->resource, global_symbols, (i < LOAD_RETRIES - 1), &resource_heap, order->required);<br>-                 ast_debug(3, "PASS %d %-46s %d %d\n", i + 1, order->resource, lres, global_symbols);<br>+                    lres = load_resource(order->resource, (i < LOAD_RETRIES - 1), &resource_heap, order->required);<br>+                 ast_debug(3, "PASS %d %-46s %d\n", i + 1, order->resource, lres);<br>                        switch (lres) {<br>                       /* These are all retryable. */<br>                        case AST_MODULE_LOAD_SUCCESS:<br>@@ -1871,15 +1847,7 @@<br>         if (load_count)<br>               ast_log(LOG_NOTICE, "%u modules will be loaded.\n", load_count);<br> <br>-        /* first, load only modules that provide global symbols */<br>-   if ((res = load_resource_list(&load_order, 1, &modulecount)) < 0) {<br>-               goto done;<br>-   }<br>-<br>- /* now load everything else */<br>-       if ((res = load_resource_list(&load_order, 0, &modulecount)) < 0) {<br>-               goto done;<br>-   }<br>+    res = load_resource_list(&load_order, &modulecount);<br> <br> done:<br>       while ((order = AST_LIST_REMOVE_HEAD(&load_order, entry))) {<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7986">change 7986</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/7986"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I33e3174d67f3b4552d3d536326dcaf0ebabb097d </div>
<div style="display:none"> Gerrit-Change-Number: 7986 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>