[Asterisk-cvs] asterisk/channels chan_zap.c,1.220,1.221

markster at lists.digium.com markster at lists.digium.com
Fri May 7 17:13:38 CDT 2004


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv18936/channels

Modified Files:
	chan_zap.c 
Log Message:
Do proper PRI locking in zt_call (not to mention lock the zt_pvt structure itself)


Index: chan_zap.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v
retrieving revision 1.220
retrieving revision 1.221
diff -u -d -r1.220 -r1.221
--- chan_zap.c	7 May 2004 18:57:17 -0000	1.220
+++ chan_zap.c	7 May 2004 21:22:46 -0000	1.221
@@ -1393,10 +1393,12 @@
 #endif
 	char callerid[256];
 	char dest[256]; /* must be same length as p->dialdest */
+	ast_mutex_lock(&p->lock);
 	strncpy(dest, rdest, sizeof(dest) - 1);
 	strncpy(p->dialdest, rdest, sizeof(dest) - 1);
 	if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
 		ast_log(LOG_WARNING, "zt_call called on %s, neither down nor reserved\n", ast->name);
+		ast_mutex_unlock(&p->lock);
 		return -1;
 	}
 	p->dialednone = 0;
@@ -1404,6 +1406,7 @@
 	{
 		/* Special pseudo -- automatically up */
 		ast_setstate(ast, AST_STATE_UP); 
+		ast_mutex_unlock(&p->lock);
 		return 0;
 	}
 	x = ZT_FLUSH_READ | ZT_FLUSH_WRITE;
@@ -1468,6 +1471,7 @@
 			x = ZT_RING;
 			if (ioctl(p->subs[SUB_REAL].zfd, ZT_HOOK, &x) && (errno != EINPROGRESS)) {
 				ast_log(LOG_WARNING, "Unable to ring phone: %s\n", strerror(errno));
+				ast_mutex_unlock(&p->lock);
 				return -1;
 			}
 			p->dialing = 1;
@@ -1479,8 +1483,10 @@
 			else
 				strcpy(p->callwaitcid, "");
 			/* Call waiting tone instead */
-			if (zt_callwait(ast))
+			if (zt_callwait(ast)) {
+				ast_mutex_unlock(&p->lock);
 				return -1;
+			}
 			/* Make ring-back */
 			if (tone_zone_play_tone(p->subs[SUB_CALLWAIT].zfd, ZT_TONE_RINGTONE))
 				ast_log(LOG_WARNING, "Unable to generate call-wait ring-back on channel %s\n", ast->name);
@@ -1528,6 +1534,7 @@
 			c = "";
 		if (strlen(c) < p->stripmsd) {
 			ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
+			ast_mutex_unlock(&p->lock);
 			return -1;
 		}
 		x = ZT_START;
@@ -1536,6 +1543,7 @@
 		if (res < 0) {
 			if (errno != EINPROGRESS) {
 				ast_log(LOG_WARNING, "Unable to start channel: %s\n", strerror(errno));
+				ast_mutex_unlock(&p->lock);
 				return -1;
 			}
 		}
@@ -1592,6 +1600,7 @@
 				x = ZT_ONHOOK;
 				ioctl(p->subs[SUB_REAL].zfd, ZT_HOOK, &x);
 				ast_log(LOG_WARNING, "Dialing failed on channel %d: %s\n", p->channel, strerror(errno));
+				ast_mutex_unlock(&p->lock);
 				return -1;
 			}
 		} else
@@ -1619,6 +1628,7 @@
 			l = NULL;
 		if (strlen(c) < p->stripmsd) {
 			ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
+			ast_mutex_unlock(&p->lock);
 			return -1;
 		}
 		p->dop.op = ZT_DIAL_OP_REPLACE;
@@ -1629,8 +1639,14 @@
 		} else {
 			strcpy(p->dop.dialstr, "");
 		}
+		if (pri_grab(p, p->pri)) {
+			ast_log(LOG_WARNING, "Failed to grab PRI!\n");
+			return -1;
+		}
 		if (!(p->call = pri_new_call(p->pri->pri))) {
 			ast_log(LOG_WARNING, "Unable to create call on channel %d\n", p->channel);
+			pri_rel(p->pri);
+			ast_mutex_unlock(&p->lock);
 			return -1;
 		}
 		p->digital = ast_test_flag(ast,AST_FLAG_DIGITAL);
@@ -1641,9 +1657,12 @@
 			(p->digital ? -1 : 
 			((p->law == ZT_LAW_ALAW) ? PRI_LAYER_1_ALAW : PRI_LAYER_1_ULAW)))) {
 			ast_log(LOG_WARNING, "Unable to setup call to %s\n", c + p->stripmsd);
+			pri_rel(p->pri);
+			ast_mutex_unlock(&p->lock);
 			return -1;
 		}
 		ast_setstate(ast, AST_STATE_DIALING);
+		pri_rel(p->pri);
 		break;
 #endif		
 	case 0:
@@ -1652,8 +1671,10 @@
 		break;		
 	default:
 		ast_log(LOG_DEBUG, "not yet implemented\n");
+		ast_mutex_unlock(&p->lock);
 		return -1;
 	}
+	ast_mutex_unlock(&p->lock);
 	return 0;
 }
 




More information about the svn-commits mailing list