diff options
author | Richard Mudgett <rmudgett@digium.com> | 2014-10-03 17:47:42 +0000 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2014-10-03 17:47:42 +0000 |
commit | 0165c5f95aa058b0884f8dec8695237cb0bef186 (patch) | |
tree | 9ca5505d80e72b574d9dad288351c760764fa8fb /main/channel.c | |
parent | 4967478d180f2a512cfb6ff83fa115aac43978c6 (diff) |
chan_pjsip: Fix deadlock when masquerading PJSIP channels.
Performing a directed call pickup resulted in a deadlock when PJSIP
channels were involved.
A masquerade needs to hold onto the channel locks while it swaps channel
information between the two channels involved in the masquerade. With
PJSIP channels, the fixup routine needed to push a fixup task onto the
PJSIP channel's serializer. Unfortunately, if the serializer was also
processing a task that needed to lock the channel, you get deadlock.
* Added a new control frame that is used to notify the channels that a
masquerade is about to start and when it has completed.
* Added the ability to query taskprocessors if the current thread is the
taskprocessor thread.
* Added the ability to suspend/unsuspend the PJSIP serializer thread so a
masquerade could fixup the PJSIP channel without using the serializer.
ASTERISK-24356 #close
Reported by: rmudgett
Review: https://reviewboard.asterisk.org/r/4034/
........
Merged revisions 424471 from http://svn.asterisk.org/svn/asterisk/branches/12
........
Merged revisions 424472 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@424473 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/channel.c')
-rw-r--r-- | main/channel.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/main/channel.c b/main/channel.c index 9100f2671..47d47b6b0 100644 --- a/main/channel.c +++ b/main/channel.c @@ -4285,6 +4285,7 @@ static int attribute_const is_visible_indication(enum ast_control_frame_type con case AST_CONTROL_MCID: case AST_CONTROL_UPDATE_RTP_PEER: case AST_CONTROL_PVT_CAUSE_CODE: + case AST_CONTROL_MASQUERADE_NOTIFY: case AST_CONTROL_STREAM_STOP: case AST_CONTROL_STREAM_SUSPEND: case AST_CONTROL_STREAM_REVERSE: @@ -4451,7 +4452,9 @@ int ast_indicate_data(struct ast_channel *chan, int _condition, ast_channel_lock(chan); /* Don't bother if the channel is about to go away, anyway. */ - if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { + if ((ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE) + || ast_check_hangup(chan)) + && condition != AST_CONTROL_MASQUERADE_NOTIFY) { res = -1; goto indicate_cleanup; } @@ -4599,6 +4602,7 @@ int ast_indicate_data(struct ast_channel *chan, int _condition, case AST_CONTROL_AOC: case AST_CONTROL_END_OF_Q: case AST_CONTROL_MCID: + case AST_CONTROL_MASQUERADE_NOTIFY: case AST_CONTROL_UPDATE_RTP_PEER: case AST_CONTROL_STREAM_STOP: case AST_CONTROL_STREAM_SUSPEND: @@ -6445,6 +6449,11 @@ static void channel_do_masquerade(struct ast_channel *original, struct ast_chann * original channel's backend. While the features are nice, which is the * reason we're keeping it, it's still awesomely weird. XXX */ + /* Indicate to each channel that a masquerade is about to begin. */ + x = 1; + ast_indicate_data(original, AST_CONTROL_MASQUERADE_NOTIFY, &x, sizeof(x)); + ast_indicate_data(clonechan, AST_CONTROL_MASQUERADE_NOTIFY, &x, sizeof(x)); + /* * The container lock is necessary for proper locking order * because the channels must be unlinked to change their @@ -6485,8 +6494,9 @@ static void channel_do_masquerade(struct ast_channel *original, struct ast_chann /* Start the masquerade channel contents rearangement. */ ast_channel_lock_both(original, clonechan); - ast_debug(4, "Actually Masquerading %s(%u) into the structure of %s(%u)\n", - ast_channel_name(clonechan), ast_channel_state(clonechan), ast_channel_name(original), ast_channel_state(original)); + ast_debug(1, "Actually Masquerading %s(%u) into the structure of %s(%u)\n", + ast_channel_name(clonechan), ast_channel_state(clonechan), + ast_channel_name(original), ast_channel_state(original)); /* * Remember the original read/write formats. We turn off any @@ -6759,6 +6769,19 @@ static void channel_do_masquerade(struct ast_channel *original, struct ast_chann ast_channel_unlock(original); ast_channel_unlock(clonechan); + /* + * Indicate to each channel that a masquerade is complete. + * + * We can still do this to clonechan even though it is a + * zombie because ast_indicate_data() will explicitly pass + * this control and ast_hangup() is held off until the + * ast_channel_masq() and ast_channel_masqr() pointers are + * cleared. + */ + x = 0; + ast_indicate_data(original, AST_CONTROL_MASQUERADE_NOTIFY, &x, sizeof(x)); + ast_indicate_data(clonechan, AST_CONTROL_MASQUERADE_NOTIFY, &x, sizeof(x)); + ast_bridge_notify_masquerade(original); if (clone_hold_state == AST_CONTROL_HOLD) { |