From 96117402b1de920584c65b62d1213a7708153821 Mon Sep 17 00:00:00 2001
From: Mark Spencer <markster@digium.com>
Date: Thu, 27 May 2004 16:50:07 +0000
Subject: [PATCH] Unlock PRI lock, fix variable pasing

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3093 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 channel.c           | 7 ++++++-
 channels/chan_zap.c | 6 ++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/channel.c b/channel.c
index f5664120e5..298f0e9615 100755
--- a/channel.c
+++ b/channel.c
@@ -1667,12 +1667,17 @@ struct ast_channel *__ast_request_and_dial(char *type, int format, void *data, i
 	struct ast_channel *chan;
 	struct ast_frame *f;
 	int res = 0;
+	char *variable;
 	chan = ast_request(type, format, data);
 	if (chan) {
 		if (oh) {
 			char *tmp, *var;
 			/* JDG chanvar */
-			tmp = oh->variable;
+			if (oh->variable)
+				variable = ast_strdupa(oh->variable);
+			else
+				variable = NULL;
+			tmp = variable;
 			/* FIXME replace this call with strsep  NOT*/
 			while( (var = strtok_r(NULL, "|", &tmp)) ) {
 				pbx_builtin_setvar( chan, var );
diff --git a/channels/chan_zap.c b/channels/chan_zap.c
index 5c7ab784a9..eed2849c38 100755
--- a/channels/chan_zap.c
+++ b/channels/chan_zap.c
@@ -6553,7 +6553,10 @@ static void *pri_dchannel(void *vpri)
 						pri->pvt[chan]->callingpres = e->ring.callingpres;
 						/* Start PBX */
 						if (pri->overlapdial && ast_matchmore_extension(NULL, pri->pvt[chan]->context, pri->pvt[chan]->exten, 1, pri->pvt[chan]->callerid)) {
+							/* Release the PRI lock while we create the channel */
+							ast_mutex_unlock(&pri->lock);
 							c = zt_new(pri->pvt[chan], AST_STATE_RING, 0, SUB_REAL, law, e->ring.ctype);
+							ast_mutex_lock(&pri->lock);
 							if (c && !pthread_create(&threadid, &attr, ss_thread, c)) {
 								if (option_verbose > 2)
 									ast_verbose(VERBOSE_PREFIX_3 "Accepting overlap call from '%s' to '%s' on channel %d, span %d\n",
@@ -6572,7 +6575,10 @@ static void *pri_dchannel(void *vpri)
 								}
 							}
 						} else  {
+							ast_mutex_unlock(&pri->lock);
+							/* Release PRI lock while we create the channel */
 							c = zt_new(pri->pvt[chan], AST_STATE_RING, 1, SUB_REAL, law, e->ring.ctype);
+							ast_mutex_lock(&pri->lock);
 							if (c) {
 								if (option_verbose > 2)
 									ast_verbose(VERBOSE_PREFIX_3 "Accepting call from '%s' to '%s' on channel %d, span %d\n",
-- 
GitLab