diff options
author | rmudgett <rmudgett@f38db490-d61c-443f-a65b-d21fe96a405b> | 2011-05-20 15:52:20 +0000 |
---|---|---|
committer | rmudgett <rmudgett@f38db490-d61c-443f-a65b-d21fe96a405b> | 2011-05-20 15:52:20 +0000 |
commit | 54472f6c4c35cb1f85791dc2cac80331ef3a0ac8 (patch) | |
tree | 4f3699108db949f466bbff06b3128db8f8d8bb47 /main/features.c | |
parent | ef96ee5356196b696ddaac9acfe8e2a264ab88ce (diff) |
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: http://svn.digium.com/svn/asterisk/trunk@319998 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/features.c')
-rw-r--r-- | main/features.c | 68 |
1 files changed, 32 insertions, 36 deletions
diff --git a/main/features.c b/main/features.c index e11081bb9..db52417a2 100644 --- a/main/features.c +++ b/main/features.c @@ -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); - - /* 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); + /* 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); + + 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; } |