[asterisk-commits] bbryant: branch 1.8 r294084 - /branches/1.8/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Nov 5 17:03:19 CDT 2010


Author: bbryant
Date: Fri Nov  5 17:03:11 2010
New Revision: 294084

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=294084
Log:
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/

Modified:
    branches/1.8/channels/chan_sip.c

Modified: branches/1.8/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/chan_sip.c?view=diff&rev=294084&r1=294083&r2=294084
==============================================================================
--- branches/1.8/channels/chan_sip.c (original)
+++ branches/1.8/channels/chan_sip.c Fri Nov  5 17:03:11 2010
@@ -5143,6 +5143,10 @@
 		} 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 @@
 	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);
-	}
-
-	/* 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);
+
+	snprintf(clen, sizeof(clen), "%d", dialog->maxforwards);
+
+	return add_header(req, "Max-Forwards", clen);
 }
 
 /*! \brief Add 'Content-Length' header and content to SIP message */




More information about the asterisk-commits mailing list