tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

asterisk 1.8.19.1 on NetBSD 6.0



Hi

Anyone is using Asterisk 1.8.19.1 on NetBSD 6.0? 

When atteptig an upgrade, I faced unpleasant crashes on startup. I have
been able to get it working again with the attached patch.

I am surprised I had to make significant changes. I wonder if the 
problems only appear with my config, or if that release is uterly 
broken. Or if it just has problems on NetBSD 6.0.

Any objection to commit this patch in pkgsrc? 

-- 
Emmanuel Dreyfus
manu%netbsd.org@localhost
$NetBSD$

Fix fox bug identified upstream, but not yet patched:
https://issues.asterisk.org/jira/browse/ASTERISK-15719

Aslo fix a crash when module load is attempted twice: since the
second attempt does not register the module, the assumption that
it can be found at the end of the loaded module list is wrong. 
Calling dlclose() at second attempt on that conditon unmaps the
module, while keeping it registered and referenced.

--- main/loader.c.orig  2012-11-05 22:36:56.000000000 +0100
+++ main/loader.c       2013-02-05 10:25:44.000000000 +0100
@@ -68,8 +68,17 @@
 #ifndef RTLD_LOCAL
 #define RTLD_LOCAL 0
 #endif
 
+#define DLCLOSE(h, name)                                                  \
+       while (h != NULL) {                                                \    
+               if (dlclose(h) != 0)                                       \
+                       ast_log(LOG_WARNING, "dlclose failed for %s: %s",  \
+                               name ? name : "", dlerror());              \
+               else                                                       \
+                       h = NULL;                                          \
+       }
+
 struct ast_module_user {
        struct ast_channel *chan;
        AST_LIST_ENTRY(ast_module_user) entry;
 };
@@ -370,10 +379,10 @@
        /* WARNING: the structure pointed to by mod is going to
           disappear when this operation succeeds, so we can't
           dereference it */
 
-       if (lib)
-               while (!dlclose(lib));
+       DLCLOSE(lib, mod->resource);
+       mod->lib = NULL;
 }
 
 static enum ast_module_load_result load_resource(const char *resource_name, 
unsigned int global_symbols_only, struct ast_heap *resource_heap, int required);
 
@@ -412,17 +421,20 @@
        }
 
        /* the dlopen() succeeded, let's find out if the module
           registered itself */
-       /* note that this will only work properly as long as
-          ast_module_register() (which is called by the module's
-          constructor) places the new module at the tail of the
-          module_list
-       */
-       if (resource_being_loaded != (mod = AST_LIST_LAST(&module_list))) {
+       AST_LIST_LOCK(&module_list);
+       AST_LIST_TRAVERSE_SAFE_BEGIN(&module_list, mod, entry) {
+               if (resource_being_loaded == mod)
+                       break;
+       }
+       AST_LIST_TRAVERSE_SAFE_END;
+       AST_LIST_UNLOCK(&module_list);
+
+       if (mod == NULL) {
                ast_log(LOG_WARNING, "Module '%s' did not register itself 
during load\n", resource_in);
                /* no, it did not, so close it and return */
-               while (!dlclose(lib));
+               DLCLOSE(lib, resource_in);
                /* note that the module's destructor will call 
ast_module_unregister(),
                   which will free the structure we allocated in 
resource_being_loaded */
                return NULL;
        }
@@ -431,9 +443,10 @@
 
        /* if we are being asked only to load modules that provide global 
symbols,
           and this one does not, then close it and return */
        if (global_symbols_only && !wants_global) {
-               while (!dlclose(lib));
+               if (!mod)
+                       DLCLOSE(lib, resource_in);
                return NULL;
        }
 
        /* This section is a workaround for a gcc 4.1 bug that has already been
@@ -456,9 +469,10 @@
                }
        }
 #endif
 
-       while (!dlclose(lib));
+       if (!mod)
+               DLCLOSE(lib, resource_in);
        resource_being_loaded = NULL;
 
        /* start the load process again */
        resource_being_loaded = ast_calloc(1, space);


Home | Main Index | Thread Index | Old Index