]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
automerge commit
authorAutomerge script <automerge@asterisk.org>
Fri, 31 Mar 2006 19:04:28 +0000 (19:04 +0000)
committerAutomerge script <automerge@asterisk.org>
Fri, 31 Mar 2006 19:04:28 +0000 (19:04 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.2-netsec@16770 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c
pbx.c

index 2412ca9a1c11628440cb08042aadd7bdd9a7d1da..c497f30d69c0350e2e24ddbb1327785cbd81ee20 100644 (file)
@@ -8781,6 +8781,18 @@ static int set_config(char *config_file, int reload)
                /*      ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
                v = v->next;
        }
+       
+       if (defaultsockfd < 0) {
+               if (!(ns = ast_netsock_bind(netsock, io, "0.0.0.0", portno, tos, socket_read, NULL))) {
+                       ast_log(LOG_ERROR, "Unable to create network socket: %s\n", strerror(errno));
+               } else {
+                       if (option_verbose > 1)
+                               ast_verbose(VERBOSE_PREFIX_2 "Binding IAX2 to default address 0.0.0.0:%d\n", portno);
+                       defaultsockfd = ast_netsock_sockfd(ns);
+                       ast_netsock_unref(ns);
+               }
+       }
+       
        if (min_reg_expire > max_reg_expire) {
                ast_log(LOG_WARNING, "Minimum registration interval of %d is more than maximum of %d, resetting minimum to %d\n",
                        min_reg_expire, max_reg_expire, max_reg_expire);
@@ -9542,9 +9554,6 @@ int load_module(void)
        struct iax2_registry *reg;
        struct iax2_peer *peer;
        
-       struct ast_netsock *ns;
-       struct sockaddr_in sin;
-       
        ast_custom_function_register(&iaxpeer_function);
 
        iax_set_output(iax_debug_output);
@@ -9553,10 +9562,6 @@ int load_module(void)
        jb_setoutput(jb_error_output, jb_warning_output, NULL);
 #endif
        
-       sin.sin_family = AF_INET;
-       sin.sin_port = htons(IAX_DEFAULT_PORTNO);
-       sin.sin_addr.s_addr = INADDR_ANY;
-
 #ifdef IAX_TRUNKING
 #ifdef ZT_TIMERACK
        timingfd = open("/dev/zap/timer", O_RDWR);
@@ -9609,19 +9614,7 @@ int load_module(void)
 
        if (ast_register_switch(&iax2_switch)) 
                ast_log(LOG_ERROR, "Unable to register IAX switch\n");
-       
-       if (defaultsockfd < 0) {
-               if (!(ns = ast_netsock_bindaddr(netsock, io, &sin, tos, socket_read, NULL))) {
-                       ast_log(LOG_ERROR, "Unable to create network socket: %s\n", strerror(errno));
-                       return -1;
-               } else {
-                       if (option_verbose > 1)
-                               ast_verbose(VERBOSE_PREFIX_2 "Binding IAX2 to default address 0.0.0.0:%d\n", IAX_DEFAULT_PORTNO);
-                       defaultsockfd = ast_netsock_sockfd(ns);
-                       ast_netsock_unref(ns);
-               }
-       }
-       
+
        res = start_network_thread();
        if (!res) {
                if (option_verbose > 1) 
diff --git a/pbx.c b/pbx.c
index 4546881c95027dd3fb55e9d23e420e8a47fa4bfa..b9662ad3dd7bc73d372ec1e3861937036e0ae7f6 100644 (file)
--- a/pbx.c
+++ b/pbx.c
@@ -514,6 +514,12 @@ AST_MUTEX_DEFINE_STATIC(applock);          /* Lock for the application list */
 struct ast_switch *switches = NULL;
 AST_MUTEX_DEFINE_STATIC(switchlock);           /* Lock for switches */
 
+/* WARNING:
+   When holding this lock, do _not_ do anything that will cause conlock
+   to be taken, unless you _already_ hold it. The ast_merge_contexts_and_delete
+   function will take the locks in conlock/hintlock order, so any other
+   paths that require both locks must also take them in that order.
+*/
 AST_MUTEX_DEFINE_STATIC(hintlock);             /* Lock for extension state notifys */
 static int stateid = 1;
 struct ast_hint *hints = NULL;
@@ -3696,9 +3702,20 @@ void ast_merge_contexts_and_delete(struct ast_context **extcontexts, const char
        int length;
        struct ast_state_cb *thiscb, *prevcb;
 
-       /* preserve all watchers for hints associated with this registrar */
        AST_LIST_HEAD_INIT(&store);
+
+       /* it is very important that this function hold the hintlock _and_ the conlock
+          during its operation; not only do we need to ensure that the list of contexts
+          and extensions does not change, but also that no hint callbacks (watchers) are
+          added or removed during the merge/delete process
+
+          in addition, the locks _must_ be taken in this order, because there are already
+          other code paths that use this order
+       */
+       ast_mutex_lock(&conlock);
        ast_mutex_lock(&hintlock);
+
+       /* preserve all watchers for hints associated with this registrar */
        for (hint = hints; hint; hint = hint->next) {
                if (hint->callbacks && !strcmp(registrar, hint->exten->parent->registrar)) {
                        length = strlen(hint->exten->exten) + strlen(hint->exten->parent->name) + 2 + sizeof(*this);
@@ -3717,10 +3734,8 @@ void ast_merge_contexts_and_delete(struct ast_context **extcontexts, const char
                        AST_LIST_INSERT_HEAD(&store, this, list);
                }
        }
-       ast_mutex_unlock(&hintlock);
 
        tmp = *extcontexts;
-       ast_mutex_lock(&conlock);
        if (registrar) {
                __ast_context_destroy(NULL,registrar);
                while (tmp) {
@@ -3740,7 +3755,6 @@ void ast_merge_contexts_and_delete(struct ast_context **extcontexts, const char
                *extcontexts = NULL;
        } else 
                ast_log(LOG_WARNING, "Requested contexts didn't get merged\n");
-       ast_mutex_unlock(&conlock);
 
        /* restore the watchers for hints that can be found; notify those that
           cannot be restored
@@ -3748,7 +3762,6 @@ void ast_merge_contexts_and_delete(struct ast_context **extcontexts, const char
        while ((this = AST_LIST_REMOVE_HEAD(&store, list))) {
                exten = ast_hint_extension(NULL, this->context, this->exten);
                /* Find the hint in the list of hints */
-               ast_mutex_lock(&hintlock);
                for (hint = hints; hint; hint = hint->next) {
                        if (hint->exten == exten)
                                break;
@@ -3771,10 +3784,12 @@ void ast_merge_contexts_and_delete(struct ast_context **extcontexts, const char
                        hint->callbacks = this->callbacks;
                        hint->laststate = this->laststate;
                }
-               ast_mutex_unlock(&hintlock);
                free(this);
        }
 
+       ast_mutex_unlock(&hintlock);
+       ast_mutex_unlock(&conlock);
+
        return; 
 }