Merged revisions 319997 via svnmerge from

https://origsvn.digium.com/svn/asterisk/branches/1.8

........
  r319997 | rmudgett | 2011-05-20 10:48:25 -0500 (Fri, 20 May 2011) | 25 lines
  
  Crash when using directed pickup applications.
  
  The directed pickup applications can cause a crash if the pickup was
  successful because the dialplan keeps executing.
  
  This patch does the following:
  
  * Completes the channel masquerade on a successful pickup before the
  application returns.  The channel is now guaranteed a zombie and must not
  continue executing the dialplan.
  
  * Changes the return value of the directed pickup applications to return
  zero if the pickup failed and nonzero(-1) if the pickup succeeded.
  
  * Made some code optimizations that no longer require re-checking the
  pickup channel to see if it is still available to pickup.
  
  (closes issue #19310)
  Reported by: remiq
  Patches:
        issue19310_v1.8_v2.patch uploaded by rmudgett (license 664)
  Tested by: alecdavis, remiq, rmudgett
  
  Review: https://reviewboard.asterisk.org/r/1221/
........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@319998 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett
2011-05-20 15:52:20 +00:00
parent f90bc95f0d
commit 0436c501c9
2 changed files with 91 additions and 103 deletions

View File

@@ -5759,21 +5759,21 @@ static int manager_park(struct mansession *s, const struct message *m)
static int find_channel_by_group(void *obj, void *arg, void *data, int flags)
{
struct ast_channel *c = data;
struct ast_channel *chan = obj;
int i;
struct ast_channel *c = data;
i = !chan->pbx &&
/* Accessing 'chan' here is safe without locking, because there is no way for
the channel to disappear from under us at this point. pickupgroup *could*
change while we're here, but that isn't a problem. */
(c != chan) &&
(c->pickupgroup & chan->callgroup) &&
ast_channel_lock(chan);
if (c != chan && (c->pickupgroup & chan->callgroup) &&
!chan->pbx &&
((chan->_state == AST_STATE_RINGING) || (chan->_state == AST_STATE_RING)) &&
!chan->masq &&
!ast_test_flag(chan, AST_FLAG_ZOMBIE);
!ast_test_flag(chan, AST_FLAG_ZOMBIE)) {
/* Return with the channel still locked on purpose */
return CMP_MATCH | CMP_STOP;
}
ast_channel_unlock(chan);
return i ? CMP_MATCH | CMP_STOP : 0;
return 0;
}
/*!
@@ -5790,35 +5790,26 @@ int ast_pickup_call(struct ast_channel *chan)
int res = -1;
ast_debug(1, "pickup attempt by %s\n", chan->name);
/* If 2 callers try to pickup the same call, allow 1 to win, and other to fail early.*/
if ((target = ast_channel_callback(find_channel_by_group, NULL, chan, 0))) {
ast_channel_lock(target);
/* The found channel is already locked. */
target = ast_channel_callback(find_channel_by_group, NULL, chan, 0);
if (target) {
ast_log(LOG_NOTICE, "pickup %s attempt by %s\n", target->name, chan->name);
/* We now have the target locked, but is the target still available to pickup */
if (!target->masq && !ast_test_flag(target, AST_FLAG_ZOMBIE) &&
((target->_state == AST_STATE_RINGING) || (target->_state == AST_STATE_RING))) {
ast_log(LOG_NOTICE, "pickup %s attempt by %s\n", target->name, chan->name);
/* A 2nd pickup attempt will bail out when we unlock the target */
if (!(res = ast_do_pickup(chan, target))) {
ast_channel_unlock(target);
if (!(res = ast_do_masquerade(target))) {
if (!ast_strlen_zero(pickupsound)) {
ast_channel_lock(target);
ast_stream_and_wait(target, pickupsound, "");
ast_channel_unlock(target);
}
} else {
ast_log(LOG_WARNING, "Failed to perform masquerade\n");
}
} else {
ast_log(LOG_WARNING, "pickup %s failed by %s\n", target->name, chan->name);
ast_channel_unlock(target);
res = ast_do_pickup(chan, target);
if (!res) {
if (!ast_strlen_zero(pickupsound)) {
/*!
* \todo We are not the bridge thread when we inject this sound
* so we need to hold the target channel lock while the sound is
* played. A better way needs to be found as this pauses the
* system.
*/
ast_stream_and_wait(target, pickupsound, "");
}
} else {
ast_channel_unlock(target);
ast_log(LOG_WARNING, "pickup %s failed by %s\n", target->name, chan->name);
}
ast_channel_unlock(target);
target = ast_channel_unref(target);
}
@@ -5882,6 +5873,11 @@ int ast_do_pickup(struct ast_channel *chan, struct ast_channel *target)
ast_manager_event_multichan(EVENT_FLAG_CALL, "Pickup", 2, chans,
"Channel: %s\r\nTargetChannel: %s\r\n", chan->name, target->name);
/* Do the masquerade manually to make sure that is is completed. */
ast_channel_unlock(target);
ast_do_masquerade(target);
ast_channel_lock(target);
return 0;
}