Merged revisions 94767 via svnmerge from
authorTilghman Lesher <tilghman@meg.abyt.es>
Mon, 24 Dec 2007 19:43:36 +0000 (19:43 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Mon, 24 Dec 2007 19:43:36 +0000 (19:43 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r94767 | tilghman | 2007-12-24 13:36:59 -0600 (Mon, 24 Dec 2007) | 5 lines

Race: we need to wait to queue a NewChannel event until after the channel is
inserted into the channel list.  The reason is because some manager users
immediately queue requests from the channel when they see that event and are
confused when Asterisk reports no such channel. (Closes issue #11632)

........

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@94768 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/channel.c

index ebcefcc..0de7ee8 100644 (file)
@@ -728,27 +728,6 @@ struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_
                ast_string_field_build_va(tmp, name, name_fmt, ap1, ap2);
                va_end(ap1);
                va_end(ap2);
                ast_string_field_build_va(tmp, name, name_fmt, ap1, ap2);
                va_end(ap1);
                va_end(ap2);
-
-               /* and now, since the channel structure is built, and has its name, let's call the
-                * manager event generator with this Newchannel event. This is the proper and correct
-                * place to make this call, but you sure do have to pass a lot of data into this func
-                * to do it here!
-                */
-               manager_event(EVENT_FLAG_CALL, "Newchannel",
-                             "Channel: %s\r\n"
-                             "ChannelState: %d\r\n"
-                             "ChannelStateDesc: %s\r\n"
-                             "CallerIDNum: %s\r\n"
-                             "CallerIDName: %s\r\n"
-                             "AccountCode: %s\r\n"
-                             "Uniqueid: %s\r\n",
-                             tmp->name, 
-                               state, 
-                             ast_state2str(state),
-                             S_OR(cid_num, ""),
-                             S_OR(cid_name, ""),
-                             tmp->accountcode,
-                             tmp->uniqueid);
        }
 
        /* Reminder for the future: under what conditions do we NOT want to track cdrs on channels? */
        }
 
        /* Reminder for the future: under what conditions do we NOT want to track cdrs on channels? */
@@ -795,6 +774,30 @@ struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_
        AST_RWLIST_INSERT_HEAD(&channels, tmp, chan_list);
        AST_RWLIST_UNLOCK(&channels);
 
        AST_RWLIST_INSERT_HEAD(&channels, tmp, chan_list);
        AST_RWLIST_UNLOCK(&channels);
 
+       /*\!note
+        * and now, since the channel structure is built, and has its name, let's
+        * call the manager event generator with this Newchannel event. This is the
+        * proper and correct place to make this call, but you sure do have to pass
+        * a lot of data into this func to do it here!
+        */
+       if (!ast_strlen_zero(name_fmt)) {
+               manager_event(EVENT_FLAG_CALL, "Newchannel",
+                       "Channel: %s\r\n"
+                       "ChannelState: %d\r\n"
+                       "ChannelStateDesc: %s\r\n"
+                       "CallerIDNum: %s\r\n"
+                       "CallerIDName: %s\r\n"
+                       "AccountCode: %s\r\n"
+                       "Uniqueid: %s\r\n",
+                       tmp->name, 
+                       state, 
+                       ast_state2str(state),
+                       S_OR(cid_num, ""),
+                       S_OR(cid_name, ""),
+                       tmp->accountcode,
+                       tmp->uniqueid);
+       }
+
        return tmp;
 }
 
        return tmp;
 }