diff options
author | bbryant <bbryant@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-11-05 22:03:11 +0000 |
---|---|---|
committer | bbryant <bbryant@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-11-05 22:03:11 +0000 |
commit | ef2a7e57457017b8842304179ddefcbdff201f9c (patch) | |
tree | 69bdbe9631395e5ebd93d40b5161a326bac73a8b /channels | |
parent | 42d999198244c02c01123a007abe88cf4438634c (diff) |
Fixed deadlock avoidance issues while locking channel when adding the
Max-Forwards header to a request.
(closes issue #17949)
(closes issue #18200)
Reported by: bwg
Review: https://reviewboard.asterisk.org/r/997/
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.8@294084 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_sip.c | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 6708a63ba..2d66e51d1 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -5143,6 +5143,10 @@ static int sip_call(struct ast_channel *ast, char *dest, int timeout) } else if (!strcasecmp(ast_var_name(current), "SIPTRANSFER_REPLACES")) { /* We're replacing a call. */ p->options->replaces = ast_var_value(current); + } else if (!strcasecmp(ast_var_name(current), "SIP_MAX_FORWARDS")) { + if (sscanf(ast_var_value(current), "%d", &(p->maxforwards)) != 1) { + ast_log(LOG_WARNING, "The SIP_MAX_FORWARDS channel variable is not a valid integer."); + } } } @@ -9082,29 +9086,17 @@ static int add_header(struct sip_request *req, const char *var, const char *valu return 0; } -/*! \brief Add 'Max-Forwards' header to SIP message */ +/*! + * \pre dialog is assumed to be locked while calling this function + * \brief Add 'Max-Forwards' header to SIP message + */ static int add_header_max_forwards(struct sip_pvt *dialog, struct sip_request *req) { char clen[10]; - const char *max = NULL; - - /* deadlock avoidance */ - while (dialog->owner && ast_channel_trylock(dialog->owner)) { - sip_pvt_unlock(dialog); - usleep(1); - sip_pvt_lock(dialog); - } - if (dialog->owner) { - max = pbx_builtin_getvar_helper(dialog->owner, "SIP_MAX_FORWARDS"); - ast_channel_unlock(dialog->owner); - } + snprintf(clen, sizeof(clen), "%d", dialog->maxforwards); - /* The channel variable overrides the peer/channel value */ - if (max == NULL) { - snprintf(clen, sizeof(clen), "%d", dialog->maxforwards); - } - return add_header(req, "Max-Forwards", max != NULL ? max : clen); + return add_header(req, "Max-Forwards", clen); } /*! \brief Add 'Content-Length' header and content to SIP message */ |