diff options
author | Kevin Harwell <kharwell@digium.com> | 2013-12-18 20:33:37 +0000 |
---|---|---|
committer | Kevin Harwell <kharwell@digium.com> | 2013-12-18 20:33:37 +0000 |
commit | 28c0cb28d0815e5e59ab99b60ac6b50e1ed9cbae (patch) | |
tree | b42967f4899ba28aea79b9a11827c814b95b62c8 /res | |
parent | 86b5e11607e2e3b7dcfb0b72d41b492ce868f31c (diff) |
channel locking: Add locking for channel snapshot creation
Original commit message by mmichelson (asterisk 12 r403311):
"This adds channel locks around calls to create channel snapshots as well
as other functions which operate on a channel and then end up
creating a channel snapshot. Functions that expect the channel to be
locked prior to being called have had their documentation updated to
indicate such."
The above was initially committed and then reverted at r403398. The problem
was found to be in core_local.c in the publish_local_bridge_message function.
The ast_unreal_lock_all function locks and adds a reference to the returned
channels and while they were being unlocked they were not being unreffed when
no longer needed. Fixed by unreffing the channels.
Also in bridge.c a lock was obtained on "other->chan", but then an attempt was
made to unlock "other" and not the previously locked channel. Fixed by
unlocking "other->chan"
(closes issue ASTERISK-22709)
Reported by: John Bigelow
........
Merged revisions 404237 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@404260 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res')
-rw-r--r-- | res/parking/parking_bridge_features.c | 2 | ||||
-rw-r--r-- | res/parking/parking_manager.c | 4 | ||||
-rw-r--r-- | res/res_agi.c | 12 | ||||
-rw-r--r-- | res/res_pjsip_refer.c | 2 | ||||
-rw-r--r-- | res/res_stasis.c | 4 |
5 files changed, 24 insertions, 0 deletions
diff --git a/res/parking/parking_bridge_features.c b/res/parking/parking_bridge_features.c index ba0ffddfb..bf211a2bd 100644 --- a/res/parking/parking_bridge_features.c +++ b/res/parking/parking_bridge_features.c @@ -530,6 +530,7 @@ static int parking_duration_callback(struct ast_bridge_channel *bridge_channel, /* Set parking timeout channel variables */ snprintf(parking_space, sizeof(parking_space), "%d", user->parking_space); + ast_channel_lock(chan); ast_channel_stage_snapshot(chan); pbx_builtin_setvar_helper(chan, "PARKING_SPACE", parking_space); pbx_builtin_setvar_helper(chan, "PARKINGSLOT", parking_space); /* Deprecated version of PARKING_SPACE */ @@ -538,6 +539,7 @@ static int parking_duration_callback(struct ast_bridge_channel *bridge_channel, pbx_builtin_setvar_helper(chan, "PARKER_FLAT", dial_string_flat); parking_timeout_set_caller_features(chan, user->lot->cfg); ast_channel_stage_snapshot_done(chan); + ast_channel_unlock(chan); /* Dialplan generation for park-dial extensions */ diff --git a/res/parking/parking_manager.c b/res/parking/parking_manager.c index 60baa6510..9d8c23618 100644 --- a/res/parking/parking_manager.c +++ b/res/parking/parking_manager.c @@ -155,7 +155,9 @@ static struct ast_parked_call_payload *parked_call_payload_from_failure(struct a RAII_VAR(struct ast_parked_call_payload *, payload, NULL, ao2_cleanup); RAII_VAR(struct ast_channel_snapshot *, parkee_snapshot, NULL, ao2_cleanup); + ast_channel_lock(chan); parkee_snapshot = ast_channel_snapshot_create(chan); + ast_channel_unlock(chan); if (!parkee_snapshot) { return NULL; } @@ -172,7 +174,9 @@ static struct ast_parked_call_payload *parked_call_payload_from_parked_user(stru struct timeval now = ast_tvnow(); const char *lot_name = pu->lot->name; + ast_channel_lock(pu->chan); parkee_snapshot = ast_channel_snapshot_create(pu->chan); + ast_channel_unlock(pu->chan); if (!parkee_snapshot) { return NULL; diff --git a/res/res_agi.c b/res/res_agi.c index ed70356dd..96d3906ac 100644 --- a/res/res_agi.c +++ b/res/res_agi.c @@ -1481,9 +1481,11 @@ static enum agi_result launch_asyncagi(struct ast_channel *chan, int argc, char to execute based on the setup info */ ast_uri_encode(agi_buffer, ami_buffer, AMI_BUF_SIZE, ast_uri_http); startblob = ast_json_pack("{s: s}", "Env", ami_buffer); + ast_channel_lock(chan); ast_channel_publish_blob(chan, agi_async_start_type(), startblob); hungup = ast_check_hangup(chan); + ast_channel_unlock(chan); for (;;) { /* * Process as many commands as we can. Commands are added via @@ -1527,7 +1529,9 @@ static enum agi_result launch_asyncagi(struct ast_channel *chan, int argc, char if (execblob && !ast_strlen_zero(cmd->cmd_id)) { ast_json_object_set(execblob, "CommandId", ast_json_string_create(cmd->cmd_id)); } + ast_channel_lock(chan); ast_channel_publish_blob(chan, agi_async_exec_type(), execblob); + ast_channel_unlock(chan); free_agi_cmd(cmd); @@ -1587,7 +1591,9 @@ async_agi_done: ast_speech_destroy(async_agi.speech); } /* notify manager users this channel cannot be controlled anymore by Async AGI */ + ast_channel_lock(chan); ast_channel_publish_blob(chan, agi_async_end_type(), NULL); + ast_channel_unlock(chan); async_agi_abort: /* close the pipe */ @@ -2716,7 +2722,9 @@ static int handle_autohangup(struct ast_channel *chan, AGI *agi, int argc, const whentohangup.tv_sec = timeout; whentohangup.tv_usec = (timeout - whentohangup.tv_sec) * 1000000.0; } + ast_channel_lock(chan); ast_channel_setwhentohangup_tv(chan, whentohangup); + ast_channel_unlock(chan); ast_agi_send(agi->fd, chan, "200 result=0\n"); return RESULT_SUCCESS; } @@ -3657,7 +3665,9 @@ static void publish_async_exec_end(struct ast_channel *chan, int command_id, con "Command", command, "ResultCode", result_code, "Result", result); + ast_channel_lock(chan); ast_channel_publish_blob(chan, agi_exec_end_type(), blob); + ast_channel_unlock(chan); } static enum agi_result agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf, int dead) @@ -3675,7 +3685,9 @@ static enum agi_result agi_handle_command(struct ast_channel *chan, AGI *agi, ch startblob = ast_json_pack("{s: i, s: s}", "CommandId", command_id, "Command", ami_cmd); + ast_channel_lock(chan); ast_channel_publish_blob(chan, agi_exec_start_type(), startblob); + ast_channel_unlock(chan); parse_args(buf, &argc, argv); c = find_command(argv, 0); diff --git a/res/res_pjsip_refer.c b/res/res_pjsip_refer.c index 91da22fde..da48e523b 100644 --- a/res/res_pjsip_refer.c +++ b/res/res_pjsip_refer.c @@ -754,7 +754,9 @@ static int refer_incoming_invite_request(struct ast_sip_session *session, struct goto end; } + ast_channel_lock(session->channel); ast_setstate(session->channel, AST_STATE_RING); + ast_channel_unlock(session->channel); ast_raw_answer(session->channel); if (!invite.bridge) { diff --git a/res/res_stasis.c b/res/res_stasis.c index 71a18a07f..32de9a041 100644 --- a/res/res_stasis.c +++ b/res/res_stasis.c @@ -637,7 +637,9 @@ static int send_start_msg(struct stasis_app *app, struct ast_channel *chan, ast_assert(chan != NULL); /* Set channel info */ + ast_channel_lock(chan); snapshot = ast_channel_snapshot_create(chan); + ast_channel_unlock(chan); if (!snapshot) { return -1; } @@ -681,7 +683,9 @@ static int send_end_msg(struct stasis_app *app, struct ast_channel *chan) ast_assert(chan != NULL); /* Set channel info */ + ast_channel_lock(chan); snapshot = ast_channel_snapshot_create(chan); + ast_channel_unlock(chan); if (snapshot == NULL) { return -1; } |